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 java.io.InputStream;

public class Main {
    public static Bitmap createBitmapFromUri(Context context, Uri uri) {

        Bitmap largeImage = null;
        try {
            InputStream iStream = context.getContentResolver().openInputStream(uri);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 2;
            largeImage = BitmapFactory.decodeStream(iStream, null, options);
            iStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return largeImage;
    }
}