Android examples for Graphics:Bitmap Size
measure Bitmap Scale
//package com.book2s; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static float measureScale(Bitmap src, int maxSize) { return measureScale(src.getWidth(), src.getHeight(), maxSize); }//from w w w . ja va 2 s . c o m public static float measureScale(String path, int maxSize) { BitmapFactory.Options op = decodeBounds(path); return measureScale(op.outWidth, op.outHeight, maxSize); } public static float measureScale(int width, int height, int maxSize) { int longSize = width > height ? width : height; if (longSize <= maxSize) { return 1; } return (float) maxSize / longSize; } public static BitmapFactory.Options decodeBounds(String path) { BitmapFactory.Options opts = createOptions(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, opts); return opts; } @SuppressWarnings("deprecation") public static BitmapFactory.Options createOptions() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; options.inDither = false; return options; } @SuppressWarnings("deprecation") public static BitmapFactory.Options createOptions( Bitmap.Config colorConfig) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = colorConfig; options.inPurgeable = true; options.inInputShareable = true; options.inDither = false; return options; } }