Nilesh Tupe
Nilesh Tupe

Reputation: 7803

Problem in creating thumbnails in android application

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

Upvotes: 2

Views: 1088

Answers (2)

Matthew
Matthew

Reputation: 44919

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 ...

Upvotes: 1

Nilesh Tupe
Nilesh Tupe

Reputation: 7803

I did like this it worked

Bitmap imagethumbnail=BitmapFactory.decodeFile(path);  //complete file path
imagethumbnail=Bitmap.createScaledBitmap(imagethumbnail, 40, 40, true);

Upvotes: 0

Related Questions