ImageUtil.java 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.epson.memcardacc;
  2. import android.graphics.Bitmap;
  3. import android.graphics.BitmapFactory;
  4. import java.io.File;
  5. public class ImageUtil {
  6. public static WidthHeight getSize(File file) {
  7. BitmapFactory.Options options = new BitmapFactory.Options();
  8. options.inJustDecodeBounds = true;
  9. BitmapFactory.decodeFile(file.toString(), options);
  10. return new WidthHeight(options.outWidth, options.outHeight);
  11. }
  12. public static int getSampleSize(WidthHeight widthHeight, WidthHeight widthHeight2) {
  13. if (widthHeight.mWidth >= widthHeight2.mWidth || widthHeight.mHeight >= widthHeight2.mHeight) {
  14. return Math.floor( Math.min(((float) widthHeight.mWidth) / ((float) widthHeight2.mWidth), ((float) widthHeight.mHeight) / ((float) widthHeight2.mHeight)));
  15. }
  16. return 1;
  17. }
  18. public static Bitmap makeThumbNail(File file, WidthHeight widthHeight) {
  19. WidthHeight size = getSize(file);
  20. BitmapFactory.Options options = new BitmapFactory.Options();
  21. options.inSampleSize = getSampleSize(size, widthHeight);
  22. return BitmapFactory.decodeFile(file.toString(), options);
  23. }
  24. public static class WidthHeight {
  25. int mHeight;
  26. int mWidth;
  27. public WidthHeight(int i, int i2) {
  28. mWidth = i;
  29. mHeight = i2;
  30. }
  31. }
  32. }