I need Thumbnail of an image . I only know about the name of image which is stored in SD card . Can anyone help me.
Asked
Active
Viewed 3.9k times
18
-
what you wanna do with that thumbnail – Mohd Mufiz Jan 01 '13 at 11:56
-
I needed the thumbnail because I kept getting `java.lang.OutOfMemoryError` when putting all image URIs directly in a GridView. – hexicle Mar 23 '18 at 19:55
4 Answers
70
Try this.
final int THUMBSIZE = 64;
Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath),
THUMBSIZE, THUMBSIZE);
Refer this for more details.

Chirag
- 56,621
- 29
- 151
- 198
-
-
-
if you are using an Uri for the image you can get the path using, for example imageUri.getPath() – xhenryx14 Oct 19 '16 at 14:44
-
11
Using MediaStore.Images.Thumbnails
you can query and get two kinds of thumbnails: MINI_KIND: 512 x 384 thumbnail MICRO_KIND: 96 x 96 thumbnail.
The advantage of using this call is that the thumbnails are cached by the MediaStore. So retrieval would be faster if the thumbnail was previously created.

Dheeraj Vepakomma
- 26,870
- 17
- 81
- 104
2
byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
Float width = new Float(imageBitmap.getWidth());
Float height = new Float(imageBitmap.getHeight());
Float ratio = width/height;
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
}
catch(Exception ex) {
}

ridoy
- 6,274
- 2
- 29
- 60
1
If you like HQ thumbnails, so use [RapidDecoder][1] library. It is simple as follow:
import rapid.decoder.BitmapDecoder;
...
Bitmap bitmap = BitmapDecoder.from(getResources(), R.drawable.image)
.scale(width, height)
.useBuiltInDecoder(true)
.decode();
Don't forget to use builtin decoder if you want to scale down less than 50% and a HQ result.

S.M.Mousavi
- 5,013
- 7
- 44
- 59