get Bitmap Factory Option - Android Graphics

Android examples for Graphics:Bitmap Option

Description

get Bitmap Factory Option

Demo Code


//package com.book2s;
import android.graphics.BitmapFactory;

public class Main {
    public static BitmapFactory.Options getBitmapFactoryOption(int width,
            int height, int twidth, int theight) {

        // Find the correct scale value. It should be the power of 2.
        final int REQUIRED_SIZE = 30;
        int width_tmp = width;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE)
                break;
            width_tmp /= 2;//from w ww.  j  ava 2s  . c  o  m
            scale *= 2;
        }

        // decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        int thumbnailHeight = (int) (height * new Float(twidth) / width);
        o2.outHeight = thumbnailHeight;
        o2.outWidth = (int) (twidth);
        return o2;
    }
}

Related Tutorials