1234567891011121314151617181920212223242526272829303132333435363738 |
- 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 Math.floor( 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;
- }
- }
- }
|