@@ -0,0 +1,1773 @@
+public class BitmapCompressUtil%7B%0A%09/**%0A%09 *@param bitmap %E8%A6%81%E8%BF%9B%E8%A1%8C%E8%B4%A8%E9%87%8F%E5%8E%8B%E7%BC%A9%E7%9A%84bitmap%E5%AF%B9%E8%B1%A1. %0A%09 *@param size  %E5%8E%8B%E7%BC%A9%E5%90%8E%E7%9A%84%E6%9C%80%E5%A4%A7%E4%BD%93%E7%A7%AF%0A%09 *%0A%09 *@return %E5%8E%8B%E7%BC%A9%E5%90%8E%E7%9A%84Bitmap%E5%AF%B9%E8%B1%A1.%0A%09 */%0A%09public static Bitmap CompressImageQuality(Bitmap bitmap,int size)%7B%0A%09%09ByteArrayOutputStream bos = new ByteArrayOutputStream();%0A%09%09bitmap.compress(Bitmap.CompressFormat.JPEG,100,bos);%0A%09%09int options=100;%0A%09%09while(bos.toByteArray().length/1024 %3E size)%7B%0A%09%09%09bos.reset();%0A%09%09%09bitmap.compress(Bitmap.CompressFormat.JPEG,options,bos);%0A%09%09%09options -= 10;%0A%09%09%7D%0A%09%09ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());%0A%09%09Bitmap compressBitmap = BitmapFactory.decodeStrem(bis,null,null);%0A%09%09return compressBitmap;%0A%09%7D%0A%09/**%0A%09 * %E5%B0%BA%E5%AF%B8%E5%8E%8B%E7%BC%A9 %E4%BD%BF%E7%94%A8%E6%97%B6%E8%A6%81%E5%AF%B9%E8%AF%A5%E6%96%B9%E6%B3%95%E7%9A%84%E5%8F%82%E6%95%B0%E4%BF%AE%E6%94%B9%EF%BC%8C%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E8%A2%AB%E5%8E%8B%E7%BC%A9%E7%9A%84%E5%9B%BE%E7%89%87%EF%BC%8C%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AA%E5%8E%8B%E7%BC%A9%E5%90%8E%E7%9A%84%E5%9B%BE%E7%89%87%0A%09 */%0A%09public void scalePic(int reqWidth,int reqHeight) %7B%0A        BitmapFactory.Options options = new BitmapFactory.Options();%0A        options.inJustDecodeBounds = true;%0A        BitmapFactory.decodeResource(getResources(), R.mipmap.demo, options);%0A        options.inSampleSize = PhotoUtil.calculateInSampleSize(options, reqWidth,reqHeight);%0A        options.inJustDecodeBounds = false;%0A        bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.demo, options);%0A%0A        postInvalidate();%0A    %7D%0A%09%0A%09public static int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight) %7B%0A        final int height = options.outHeight;%0A        final int width = options.outWidth;%0A        int inSampleSize = 1;%0A        if (height %3E reqHeight %7C%7C width %3E reqWidth) %7B%0A            final int heightRatio = Math.round((float) height / (float) reqHeight);%0A            final int widthRatio = Math.round((float) width / (float) reqWidth);%0A            inSampleSize = heightRatio %3C widthRatio ? heightRatio : widthRatio;%0A        %7D%0A        return inSampleSize;%0A    %7D%0A%7D%0A

add bitmap compress util class for compressing bitmap