Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.BitmapFactory;

import android.widget.ImageView;

import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    public static void setImageViewWidthBitmap(String imgPath, ImageView imageView) throws IOException {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(imgPath, options);
        options.inSampleSize = Math.min(options.outWidth / imageView.getWidth(),
                options.outHeight / imageView.getWidth());
        options.inJustDecodeBounds = false;
        options.inPurgeable = true;
        options.inInputShareable = true;

        FileInputStream fis = new FileInputStream(imgPath);
        imageView.setImageBitmap(BitmapFactory.decodeFileDescriptor(fis.getFD(), null, options));
    }
}