package com.epson.memcardacc;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.File;

public class ImageUtil {
    public static WidthHeight getSize(File file) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.toString(), options);
        return new WidthHeight(options.outWidth, options.outHeight);
    }

    public static int getSampleSize(WidthHeight widthHeight, WidthHeight widthHeight2) {
        if (widthHeight.mWidth >= widthHeight2.mWidth || widthHeight.mHeight >= widthHeight2.mHeight) {
            return (int) Math.floor((double) Math.min(((float) widthHeight.mWidth) / ((float) widthHeight2.mWidth), ((float) widthHeight.mHeight) / ((float) widthHeight2.mHeight)));
        }
        return 1;
    }

    public static Bitmap makeThumbNail(File file, WidthHeight widthHeight) {
        WidthHeight size = getSize(file);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = getSampleSize(size, widthHeight);
        return BitmapFactory.decodeFile(file.toString(), options);
    }

    public static class WidthHeight {
        int mHeight;
        int mWidth;

        public WidthHeight(int i, int i2) {
            mWidth = i;
            mHeight = i2;
        }
    }
}
