I am facing this issue but unable to resolve. My problem goes like this:
- I have a list view. My list row contains an image view and one text view
- I have 20 images each of 12 MB size stored in my SD card
- I have to set these images in imageView of my list view
I am able to do it by following code. This I am doing in getView method of my custom adapter:
public View getView (int position, View convertView, ViewGroup parent) {
//other stuffs like recycling, view holder etc...
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inSampleSize = 4; // tried with 8,12 too
Bitmap bitmap = BitmapFactory.decodeFile(imageUri, opt);
holder.imageView.setImageBitmap(bitmap);
return convertView;
}
Now this code works fine with small images but plays havoc for image of large size. Application crashes with OutOfMemoryError. If I try to increase inSampleSize to 8 or 12, it works but image quality drastically comes down and image doesn’t look original image at all. I tried with imageView.setImageURI(imageUri) also but documentation suggests to use setImageBitmap only.
Now please someone help me to rectify this issue. How can I resolve this without compromising with image quality?
Try setting inSampleSize to 2 or 4, and scale width and height down using the
Matrixclass.But as you said in another answer, this may hit performance.
Second option. Before instantiating the Adapter class, get a Cursor object to thumbnail images and pass the cursor into the constructor of the adapter, making it a class varaible. Use the same cursor on every view row in the ListView.
Something like that. I did it in a hurry. Good luck =)