Get the image bitmap that resizing to maximum size of limit. - Android Graphics

Android examples for Graphics:Bitmap Size

Description

Get the image bitmap that resizing to maximum size of limit.

Demo Code


//package com.java2s;

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

public class Main {

    public static Bitmap getSafeResizingBitmap(String strImagePath) {

        BitmapFactory.Options options = getBitmapSize(strImagePath);

        if (options == null)
            return null;

        options.inJustDecodeBounds = false;
        options.inDither = false;/*w w w.  jav  a 2s  .c  om*/
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        options.inPurgeable = true;

        Bitmap photo = BitmapFactory.decodeFile(strImagePath, options);

        return photo;
    }
    public static BitmapFactory.Options getBitmapSize(String strImagePath) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        //Bitmap photo = BitmapFactory.decodeFile(strPath, options);
        BitmapFactory.decodeFile(strImagePath, options);

        return options;
    }
}

Related Tutorials