get Bitmap Options With In Sample Size - Android Graphics

Android examples for Graphics:Bitmap Sample Size

Description

get Bitmap Options With In Sample Size

Demo Code


//package com.java2s;

import android.graphics.BitmapFactory;

public class Main {

    public static BitmapFactory.Options getOptionsWithInSampleSize(
            String filePath, int maxWidth) {
        BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bitmapOptions.inJustDecodeBounds = true;// outHeight()
        // outWidth()
        BitmapFactory.decodeFile(filePath, bitmapOptions);
        bitmapOptions.inJustDecodeBounds = false;
        int inSampleSize = bitmapOptions.outWidth / (maxWidth / 10);// 16016
        if (inSampleSize % 10 != 0) {
            inSampleSize += 10;// 
        }// ww w .  j  ava 2 s  . c om
        inSampleSize = inSampleSize / 10;
        if (inSampleSize <= 0) {// 200
            inSampleSize = 1;// 
        }
        bitmapOptions.inSampleSize = inSampleSize;
        return bitmapOptions;
    }
}

Related Tutorials