开发者

Problem in creating thumbnails in android application

开发者 https://www.devze.com 2023-02-14 17:32 出处:网络
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 开发者

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号