load Full Bitmap Image from Uri - Android Graphics

Android examples for Graphics:Bitmap Read

Description

load Full Bitmap Image from Uri

Demo Code


//package com.java2s;
import android.net.Uri;
import android.content.Context;
import android.provider.MediaStore;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main {
    public static Bitmap loadFullImage(Context context, Uri photoUri) {
        Cursor photoCursor = null;

        try {/*from  w  w w . j a  v  a2s .  c om*/
            // Attempt to fetch asset filename for image
            String[] projection = { MediaStore.Images.Media.DATA };
            photoCursor = context.getContentResolver().query(photoUri,
                    projection, null, null, null);

            if (photoCursor != null && photoCursor.getCount() == 1) {
                photoCursor.moveToFirst();
                String photoFilePath = photoCursor.getString(photoCursor
                        .getColumnIndex(MediaStore.Images.Media.DATA));

                // Load image from path
                return BitmapFactory.decodeFile(photoFilePath, null);
            }
        } finally {
            if (photoCursor != null) {
                photoCursor.close();
            }
        }

        return null;
    }
}

Related Tutorials