get Down Size Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Operation

Description

get Down Size Bitmap

Demo Code


//package com.java2s;
import java.io.FileNotFoundException;

import android.content.Context;

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

public class Main {
    public static Bitmap getDownSizeBitmap(Context ctx, String paramString,
            int paramInt) {
        try {/*  w ww. j a  v a 2  s . co m*/
            BitmapFactory.Options localOptions = new BitmapFactory.Options();
            localOptions.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(ctx.openFileInput(paramString),
                    null, localOptions);
            localOptions.inSampleSize = 1;
            for (float f = localOptions.outWidth * localOptions.outHeight
                    / paramInt; f > 2.0F; f /= 4.0F) {
                localOptions.inSampleSize = (2 * localOptions.inSampleSize);
            }
            localOptions.inJustDecodeBounds = false;
            Bitmap localBitmap = BitmapFactory.decodeStream(
                    ctx.openFileInput(paramString), null, localOptions);
            return localBitmap;
        } catch (FileNotFoundException localFileNotFoundException) {
            localFileNotFoundException.printStackTrace();
        }
        return null;
    }
}

Related Tutorials