decode Uri As Bitmap - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

decode Uri As Bitmap

Demo Code

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 decodeUriAsBitmap(Context context, Uri uri) {
    Bitmap bitmap = null;//from   w  w w . j  a v  a 2  s  .c o m
    try {
      bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      return null;
    }
    return bitmap;
  }

}

Related Tutorials