Android examples for Graphics:Bitmap Scale
shrink Bitmap To Suitable
//package com.book2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static Bitmap featBitmapToSuitable(String path, int suitableSize, float factor) { Bitmap bitmap = null;/* w w w . j a v a 2 s. c o m*/ try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); options.inJustDecodeBounds = false; options.inSampleSize = 1; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; int bitmap_w = options.outWidth; int bitmap_h = options.outHeight; int max_edge = bitmap_w > bitmap_h ? bitmap_w : bitmap_h; while (max_edge / (float) suitableSize > factor) { options.inSampleSize <<= 1; max_edge >>= 1; } return BitmapFactory.decodeFile(path, options); } catch (Exception e) { } return bitmap; } }