get Bitmap By Uri - Android android.graphics

Android examples for android.graphics:Bitmap Load Save

Description

get Bitmap By Uri

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

}

Related Tutorials