get Bitmap By Uri - Android Graphics

Android examples for Graphics:Bitmap Read

Description

get Bitmap By Uri

Demo Code


//package com.java2s;

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 a va2s  .c  o  m*/
        try {
            bitmap = BitmapFactory.decodeStream(context
                    .getContentResolver().openInputStream(uri));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
        return bitmap;
    }
}

Related Tutorials