Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to create runtime thumbnail

Tags:

android

I have a large sized image. At runtime, I want to read the image from storage and scale it so that its weight and size gets reduced and I can use it as a thumbnail. When a user clicks on the thumbnail, I want to display the full-sized image.

like image 856
d-man Avatar asked Apr 05 '10 06:04

d-man


2 Answers

Try this

Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath), THUMBSIZE, THUMBSIZE); 

This Utility is available from API_LEVEl 8. [Source]

like image 112
Dax Avatar answered Sep 20 '22 03:09

Dax


My Solution

byte[] imageData = null;          try              {              final int THUMBNAIL_SIZE = 64;              FileInputStream fis = new FileInputStream(fileName);             Bitmap imageBitmap = BitmapFactory.decodeStream(fis);              imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);              ByteArrayOutputStream baos = new ByteArrayOutputStream();               imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);             imageData = baos.toByteArray();          }         catch(Exception ex) {          } 
like image 38
kakopappa Avatar answered Sep 21 '22 03:09

kakopappa