decode Uri As Bitmap - Android Graphics

Android examples for Graphics:Bitmap URL

Description

decode Uri As Bitmap

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import java.io.FileNotFoundException;

public class Main {
    public static Bitmap decodeUriAsBitmap(Context context, Uri uri) {
        Bitmap bitmap = null;//from   w  ww  . j  a  v  a2s.  c om
        try {
            bitmap = BitmapFactory.decodeStream(context
                    .getContentResolver().openInputStream(uri));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
        return bitmap;
    }
}

Related Tutorials