Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;

import android.support.annotation.NonNull;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static Bitmap getBitmapFromUri(@NonNull Context context, @NonNull Uri uri) throws IOException {
        InputStream stream = context.getContentResolver().openInputStream(uri);
        Bitmap rawImage = BitmapFactory.decodeStream(stream);

        try {
            stream.close();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

        return rawImage;
    }
}