انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
thumbnail برای گریدویو- فولدر خاص یا در زمان اجرا (در برنامه نویسی اندروید)

thumbnail برای گریدویو- فولدر خاص یا در زمان اجرا (در برنامه نویسی اندروید)

#1
با سلام :
من یک آلبوم گریدویویی دارم که زمانی که کاربر می تواند به این گریدویو با گرفتن عکس یا import کردن، عکس اضافه کند . زمانی که مثلا عکس بگیرد وارد یک اکتیویتی دیگر می شود که عکس را می بیند و می تواند به آن متن و صوت اضافه کند که با sqlite به هم مرتبط می شوند. می خواهم سرعت لود شدن در گریدویو را افزایش بدهم بهتری راه چیست ؟
1- هنگامی که عکس جدید گرفته می شود  از عکس اورجینال یک thumbnail درست کنم و آن را در یک فولدر جدید قرار دهم و گریدویو را از این فولدر جدید که فقط thumbnail در آن هست لود شود؟
2- در زمان اجرا و در متد getview در imageadapter ، برای هر عکس thumbnail را بگیرم برای مورد دوم این کد را استفاده کردم:
با تشکر

کد پی‌اچ‌پی:
@Override
  
public View getView(int positionView convertViewViewGroup parent) {
   
ImageView imageView;
         if (
convertView == null) {  // if it's not recycled, initialize some attributes
             
imageView = new ImageView(mContext);
             
imageView.setLayoutParams(new GridView.LayoutParams(220220));
             
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
             
imageView.setPadding(8888);
         } else {
             
imageView = (ImageViewconvertView;
         }

         
Bitmap bm decodeSampledBitmapFromUri(itemList.get(position), 220220);

         
imageView.setImageBitmap(bm);
         return 
imageView;
  }

  public 
Bitmap decodeSampledBitmapFromUri(String pathint reqWidthint reqHeight) {

   
Bitmap bm null;
   
// First decode with inJustDecodeBounds=true to check dimensions
   
final BitmapFactory.Options options = new BitmapFactory.Options();
   
options.inJustDecodeBounds true;
   
BitmapFactory.decodeFile(pathoptions);

   
// Calculate inSampleSize
   
options.inSampleSize calculateInSampleSize(optionsreqWidthreqHeight);

   
// Decode bitmap with inSampleSize set
   
options.inJustDecodeBounds false;
   
bm BitmapFactory.decodeFile(pathoptions); 

   return 
bm;   
  }

  public 
int calculateInSampleSize(

   
BitmapFactory.Options optionsint reqWidthint reqHeight) {
   
// Raw height and width of image
   
final int height options.outHeight;
   final 
int width options.outWidth;
   
int inSampleSize 1;

   if (
height reqHeight || width reqWidth) {
    if (
width height) {
     
inSampleSize Math.round((float)height / (float)reqHeight);    
    } else {
     
inSampleSize Math.round((float)width / (float)reqWidth);    
    }   
   }

   return 
inSampleSize;    
  }

 } 
 
پاسخ
 سپاس شده توسط mina73


پیام‌های این موضوع
thumbnail برای گریدویو- فولدر خاص یا در زمان اجرا (در برنامه نویسی اندروید) - توسط hamidrezass - ۱۳۹۴/۰۵/۲۴, ۰۵:۲۶ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان