Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thumbnail of an image from resources

I want to make a thumbnail of an image.The image is in the resourse-drawable.Can anyone help me.

like image 766
Sreedev Avatar asked Jan 18 '23 09:01

Sreedev


1 Answers

try this code

     im=(ImageView)findViewById(R.id.imageView1);

    byte[] imageData = null;

    try 
    {

    final int THUMBNAIL_SIZE = 64;
    //InputStream is=getAssets().open("apple-android-battle.jpg");
    FileInputStream fis = new FileInputStream("/sdcard/apple.jpg");
    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();
    im.setImageBitmap(imageBitmap);
    }
    catch(Exception ex) {

    }
like image 142
Jackson Chengalai Avatar answered Jan 20 '23 16:01

Jackson Chengalai