load Full Image - Android android.graphics

Android examples for android.graphics:Image Load Save

Description

load Full Image

Demo Code

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;

public class Main {

  public static Bitmap loadFullImage(Context context, Uri photoUri) {
    Cursor photoCursor = null;/* www  . jav a2s . c  o  m*/

    try {
      // 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