i had a problem with load images as bitmap , therefore i use the method:
"decodeSampledBitmapFromFile"
(the implementation is included)
and i also saved all the bitmaps on the SdCard and every time that i need the Bitmap i load it from the Path which it's stored with the parameters:
decodeSampledBitmapFromFile(path,150,100);
Bitmap image_profile =decodeSampledBitmapFromFile(path,150,100);
and set the image Bitmap into the imageView that i need (every time that i need a image i load it from the sdCard.
however i still get an OutOfMemoryException after load about 20 images.
So, what is the solution for the OutOfMemoryException?
why even after load small number of images (about 20) i get an OutOfMemoryException?
what is the secret of application like facebook, instagram or youtube that they suceesseed
to load huge number of images without Exception?
i tried everything however i still get Exception.
anyOne has further suggestions what can i implement in order to avoid this exception?
thanks alot
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight)
{ // BEST QUALITY MATCH
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float)height / (float)reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
//if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
inSampleSize = Math.round((float)width / (float)reqWidth);
}
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}