get Bitmap Thumbnail - Android Graphics

Android examples for Graphics:Bitmap Thumbnail

Description

get Bitmap Thumbnail

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

public class Main {
    public static Bitmap getThumbnail(Bitmap bitmap, double sizeWidth) {
        Bitmap imgBitmap = bitmap;/*from   w  w  w .j a  v a 2s . c  o  m*/

        int h = imgBitmap.getHeight();
        int w = imgBitmap.getWidth();
        if ((w > h) && (w > sizeWidth)) {
            double ratio = sizeWidth / w;
            w = (int) sizeWidth;
            h = (int) (ratio * h);
        } else if ((h > w) && (h > sizeWidth)) {
            double ratio = sizeWidth / h;
            h = (int) sizeWidth;
            w = (int) (ratio * w);
        }

        Bitmap scaled = Bitmap.createScaledBitmap(imgBitmap, w, h, true);

        return scaled;
    }
}

Related Tutorials