با سلام :
من یک آلبوم گریدویویی دارم که زمانی که کاربر می تواند به این گریدویو با گرفتن عکس یا import کردن، عکس اضافه کند . زمانی که مثلا عکس بگیرد وارد یک اکتیویتی دیگر می شود که عکس را می بیند و می تواند به آن متن و صوت اضافه کند که با sqlite به هم مرتبط می شوند. می خواهم سرعت لود شدن در گریدویو را افزایش بدهم بهتری راه چیست ؟
1- هنگامی که عکس جدید گرفته می شود از عکس اورجینال یک thumbnail درست کنم و آن را در یک فولدر جدید قرار دهم و گریدویو را از این فولدر جدید که فقط thumbnail در آن هست لود شود؟
2- در زمان اجرا و در متد getview در imageadapter ، برای هر عکس thumbnail را بگیرم برای مورد دوم این کد را استفاده کردم:
با تشکر
من یک آلبوم گریدویویی دارم که زمانی که کاربر می تواند به این گریدویو با گرفتن عکس یا import کردن، عکس اضافه کند . زمانی که مثلا عکس بگیرد وارد یک اکتیویتی دیگر می شود که عکس را می بیند و می تواند به آن متن و صوت اضافه کند که با sqlite به هم مرتبط می شوند. می خواهم سرعت لود شدن در گریدویو را افزایش بدهم بهتری راه چیست ؟
1- هنگامی که عکس جدید گرفته می شود از عکس اورجینال یک thumbnail درست کنم و آن را در یک فولدر جدید قرار دهم و گریدویو را از این فولدر جدید که فقط thumbnail در آن هست لود شود؟
2- در زمان اجرا و در متد getview در imageadapter ، برای هر عکس thumbnail را بگیرم برای مورد دوم این کد را استفاده کردم:
با تشکر
کد پیاچپی:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(220, 220));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
Bitmap bm = decodeSampledBitmapFromUri(itemList.get(position), 220, 220);
imageView.setImageBitmap(bm);
return imageView;
}
public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {
Bitmap bm = null;
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(path, options);
return bm;
}
public int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int 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;
}
}