Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import java.io.FileNotFoundException; import java.io.IOException; public class Main { /** * Reads a Bitmap from an Uri. * * @param context * @param selectedImage * @return Bitmap */ public static Bitmap readBitmap(Context context, Uri selectedImage) { Bitmap bm = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inScaled = false; // options.inSampleSize = 3; AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = context.getContentResolver().openAssetFileDescriptor(selectedImage, "r"); } catch (FileNotFoundException e) { return null; } finally { try { bm = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options); fileDescriptor.close(); } catch (IOException e) { return null; } } return bm; } }