Android Bitmap Thumbnail Create getImageThumbnail(String imagePath, int width, int height)

Here you can find the source of getImageThumbnail(String imagePath, int width, int height)

Description

get Image Thumbnail

Declaration

public static Bitmap getImageThumbnail(String imagePath, int width,
        int height) 

Method Source Code

//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;

public class Main {

    public static Bitmap getImageThumbnail(String imagePath, int width,
            int height) {
        Bitmap bitmap = null;//  w w  w  .  j  a  va 2 s.  c  om
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        bitmap = BitmapFactory.decodeFile(imagePath, options);
        options.inJustDecodeBounds = false; 
        int h = options.outHeight;
        int w = options.outWidth;
        int beWidth = w / width;
        int beHeight = h / height;
        int be = 1;
        if (beWidth < beHeight) {
            be = beWidth;
        } else {
            be = beHeight;
        }
        if (be <= 0) {
            be = 1;
        }
        options.inSampleSize = be;
        bitmap = BitmapFactory.decodeFile(imagePath, options);
        bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
                ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
        return bitmap;
    }
}

Related

  1. extractThumbnail(Bitmap source, int width, int height)
  2. extractThumbnail(Bitmap source, int width, int height, int options)
  3. cacheAvatar(Context context, URI uri, Bitmap avatar)