@@ -0,0 +1,3249 @@
+package com.yxkang.android.util;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0Aimport android.util.Log;%0A%0Aimport java.io.FileDescriptor;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0A%0A/**%0A * Bitmap Utils%0A */%0Apublic class BitmapUtil %7B%0A%0A    private static final String TAG = %22BitmapUtil%22;%0A    private static final int UNCONSTRAINED = -1;%0A%0A    public static Bitmap createImageThumbnail(String filePath, int reqWidth, int reqHeight) %7B%0A        Bitmap bm = null;%0A        FileInputStream stream = null;%0A        try %7B%0A            stream = new FileInputStream(filePath);%0A            FileDescriptor fd = stream.getFD();%0A            BitmapFactory.Options options = new BitmapFactory.Options();%0A            options.inSampleSize = 1;%0A            options.inJustDecodeBounds = true;%0A            BitmapFactory.decodeFileDescriptor(fd, null, options);%0A            if (options.mCancel %7C%7C options.outWidth == -1 %7C%7C options.outHeight == -1) %7B%0A                return null;%0A            %7D%0A            options.inSampleSize = computeSampleSize(options, Math.min(reqWidth, reqHeight), reqWidth * reqHeight);%0A            Log.d(TAG, String.valueOf(options.inSampleSize));%0A            options.inJustDecodeBounds = false;%0A%0A            options.inDither = false;%0A            options.inPreferredConfig = Bitmap.Config.ARGB_8888;%0A            bm = BitmapFactory.decodeFileDescriptor(fd, null, options);%0A        %7D catch (IOException ex) %7B%0A            Log.e(TAG, %22%22, ex);%0A        %7D catch (OutOfMemoryError oom) %7B%0A            Log.e(TAG, %22Unable to decode file %22 + filePath + %22. OutOfMemoryError.%22, oom);%0A        %7D finally %7B%0A            try %7B%0A                if (stream != null) %7B%0A                    stream.close();%0A                %7D%0A            %7D catch (IOException ex) %7B%0A                Log.e(TAG, %22%22, ex);%0A            %7D%0A        %7D%0A        return bm;%0A    %7D%0A%0A    private static int computeSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) %7B%0A        int initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels);%0A%0A        int roundedSize;%0A        if (initialSize %3C= 8) %7B%0A            roundedSize = 1;%0A            while (roundedSize %3C initialSize) %7B%0A                roundedSize %3C%3C= 1;%0A            %7D%0A        %7D else %7B%0A            roundedSize = (initialSize + 7) / 8 * 8;%0A        %7D%0A%0A        return roundedSize;%0A    %7D%0A%0A    private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) %7B%0A        double w = options.outWidth;%0A        double h = options.outHeight;%0A%0A        int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));%0A        int upperBound = (minSideLength == UNCONSTRAINED) ? 128%0A                : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));%0A%0A        if (upperBound %3C lowerBound) %7B%0A            // return the larger one when there is no overlapping zone.%0A            return lowerBound;%0A        %7D%0A%0A        if ((maxNumOfPixels == UNCONSTRAINED) && (minSideLength == UNCONSTRAINED)) %7B%0A            return 1;%0A        %7D else if (minSideLength == UNCONSTRAINED) %7B%0A            return lowerBound;%0A        %7D else %7B%0A            return upperBound;%0A        %7D%0A    %7D%0A%7D%0A

add BitmapUtil