Here you can find the source of readBitmapAutoSize(String filePath, int outWidth, int outHeight)
public static Bitmap readBitmapAutoSize(String filePath, int outWidth, int outHeight)
//package com.java2s; import java.io.BufferedInputStream; import java.io.FileInputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static Bitmap readBitmapAutoSize(String filePath, int outWidth, int outHeight) { FileInputStream fs = null; BufferedInputStream bs = null; try {//from w ww . j a v a2s . co m fs = new FileInputStream(filePath); bs = new BufferedInputStream(fs); BitmapFactory.Options options = setBitmapOption(filePath, outWidth, outHeight); return BitmapFactory.decodeStream(bs, null, options); } catch (Exception e) { e.printStackTrace(); } finally { try { bs.close(); fs.close(); } catch (Exception e) { e.printStackTrace(); } } return null; } private static BitmapFactory.Options setBitmapOption(String file, int width, int height) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inJustDecodeBounds = true; 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; } }