I am working on a file manager kind of application in android in which i want to create thumbnails of the images.Thumbnails are getting created but the application often force closes giving out 开发者_StackOverflow中文版Out Of Memory Exception...
i tried out following code
icon.setImageURI(Uri.parse(path));
icon.setScaleType(ScaleType.FIT_XY);
icon.setLayoutParams(new LinearLayout.LayoutParams(30,30));
addView(icon);
Make sure that when you load the images you specify a sample rate to BitmapFactory.Options. This will keep your bitmaps from getting too big:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 4;
... use a BitmapFactory method, passing opts ...
I did like this it worked
Bitmap imagethumbnail=BitmapFactory.decodeFile(path); //complete file path
imagethumbnail=Bitmap.createScaledBitmap(imagethumbnail, 40, 40, true);
精彩评论