Android examples for Graphics:Bitmap File
load Bitmap and scale
//package com.book2s; import java.io.FileNotFoundException; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; public class Main { public static Bitmap loadBitmap(Context context, Uri imageUri) throws FileNotFoundException { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true;/* w w w .jav a 2s. c om*/ BitmapFactory.decodeStream(context.getContentResolver() .openInputStream(imageUri), null, o); final int REQUIRED_SIZE = 140; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) { break; } width_tmp /= 2; height_tmp /= 2; scale *= 2; } BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; return BitmapFactory.decodeStream(context.getContentResolver() .openInputStream(imageUri), null, o2); } }