show Down Size Image in ImageView - Android User Interface

Android examples for User Interface:ImageView

Description

show Down Size Image in ImageView

Demo Code


//package com.java2s;
import java.io.FileNotFoundException;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.widget.ImageView;

public class Main {
    public static void showDownSizeImage(Context context,
            ImageView mInputImgView, String mInputImage, int i) {
        Bitmap localBitmap = getDownSizeBitmap(context, mInputImage, i);
        if (localBitmap != null) {
            mInputImgView.setImageBitmap(localBitmap);
        }/*from ww  w .  j a v a2 s  .co m*/
    }

    public static Bitmap getDownSizeBitmap(Context ctx, String paramString,
            int paramInt) {
        try {
            BitmapFactory.Options localOptions = new BitmapFactory.Options();
            localOptions.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(ctx.openFileInput(paramString),
                    null, localOptions);
            localOptions.inSampleSize = 1;
            for (float f = localOptions.outWidth * localOptions.outHeight
                    / paramInt; f > 2.0F; f /= 4.0F) {
                localOptions.inSampleSize = (2 * localOptions.inSampleSize);
            }
            localOptions.inJustDecodeBounds = false;
            Bitmap localBitmap = BitmapFactory.decodeStream(
                    ctx.openFileInput(paramString), null, localOptions);
            return localBitmap;
        } catch (FileNotFoundException localFileNotFoundException) {
            localFileNotFoundException.printStackTrace();
        }
        return null;
    }
}

Related Tutorials