I use the following code to load images to rows in a ListActivity.
URL url = new URL(drink.getImageUri());
InputStream fis = url.openStream();
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(fis, null, o);
int scale = 1;
if (o.outHeight > imageMaxSize || o.outWidth > imageMaxSize) {
scale = (int) Math.pow(2, (int) Math.round(Math.log((imageMaxSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))));
}
fis.close();
fis = url.openStream();
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmap = BitmapFactory.decodeStream(fis, null, o2);
fis.close();
imageMaxSize is screenHeight/7 so the each image should be fairly small.
Have I done something wrong in the code above? All errors I got is in the second last line where I attempt to actually load the bitmap.
Thanks in advance Roland
The problem with the code above whas the following block:
It simply doesn't do its job. WillyTates comment of trying to increase the scaling made me check the result of the calculation and it always returned 1.
Now when I fixed it so I get scale of 4 or 8 it works a lot better and I havn't been able to get the error back.
Thanks Roland