Tuesday, October 18, 2011

Create Thumbnails of Image

Create Thumbnails of image/Compress Imgage .

This program for to display Thumbnails of images store in sdcard or any other location.

=========================================================

BitmapFactory.Options op=new BitmapFactory.Options();

InputStream f = null;

try {

f = new FileInputStream(files[position].getAbsolutePath());

} catch (FileNotFoundException e) {

e.printStackTrace();

}

final int REQUIRED_SIZE=1024;

int width_tmp=op.outWidth, height_tmp=op.outHeight;

int scale=1;

while(true){

if(width_tmp/2

break;

width_tmp/=2;

height_tmp/=2;

scale*=2;

}

op.inSampleSize=scale;

Bitmap b2; b2=Bitmap.createScaledBitmap(BitmapFactory.decodeFile(files[position].getAbsolutePath(),op),50, 50,true);

imageView.setImageBitmap(b2);

=========================================================

Here while loop is used because image file can me more than 1 mb in size so there may be cresh or it can take more time to set in imgageview, so we reducing scale of that image.



No comments:

Post a Comment