package com.celerysoft.imagepager.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * Created by Administrator on 2015-11-20.
 */
public class ImageUtil {
    /**
     * get bitmap by file absolute path
     * @param fileName
     * @return
     */
    public static final Bitmap getBitmap(Context context, String fileName) {
        Bitmap bitmap = null;
        try {
            int targetWidth = (int) (context.getResources().getDisplayMetrics().widthPixels * 0.8);
            int targetHeight = context.getResources().getDisplayMetrics().heightPixels;

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(fileName, options);

            int photoWidth = options.outWidth;
            int photoHeight = options.outHeight;

            int scaleFactor = Math.min(photoWidth/targetWidth, photoHeight/targetHeight);

            options.inSampleSize = Math.max(1, (int) Math.ceil(Math.max(
                    (double) options.outWidth / 1024f,
                    (double) options.outHeight / 1024f)));
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFile(fileName, options);
        } catch (OutOfMemoryError error) {
            error.printStackTrace();
        }

        return bitmap;
    }
}

@@ -136,16 +136,63 @@
 Factory;
+%0Aimport android.util.Log;%0A%0Aimport java.io.File;
 %0A%0A/**%0A *
@@ -261,16 +261,89 @@
 eUtil %7B%0A
+%0A    private static final String TAG = ImageUtil.class.getSimpleName();%0A%0A
     /**%0A
@@ -400,20 +400,39 @@
 ram file
-Name
+Path file absolute path
 %0A     * 
@@ -438,16 +438,23 @@
  @return
+ bitmap
 %0A     */
@@ -527,15 +527,219 @@
 file
-Name) %7B
+Path) %7B%0A        File f = new File(filePath);%0A        if (f != null) %7B%0A            if (!f.exists()) %7B%0A                Log.w(TAG, %22No such file: %22 + filePath);%0A                return null;%0A            %7D%0A        %7D%0A
 %0A   
@@ -1121,36 +1121,36 @@
 .decodeFile(file
-Name
+Path
 , options);%0A%0A   
@@ -1619,20 +1619,20 @@
 ile(file
-Name
+Path
 , option

update ImageUtil