set Bitmap Option - Android Graphics

Android examples for Graphics:Bitmap Option

Description

set Bitmap Option

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {

    private static BitmapFactory.Options setBitmapOption(String file,
            int width, int height) {

        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inJustDecodeBounds = true;//from   w  w  w  .j  a v a 2  s  .c o m
        BitmapFactory.decodeFile(file, opt);

        int outWidth = opt.outWidth; 
        int outHeight = opt.outHeight;
        opt.inDither = false;
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inSampleSize = 1;
        if (outWidth != 0 && outHeight != 0 && width != 0 && height != 0) {
            int sampleSize = (outWidth / width + outHeight / height) / 2;
            opt.inSampleSize = sampleSize;
        }

        opt.inJustDecodeBounds = false;
        return opt;
    }
}

Related Tutorials