私は同じ問題を抱えていたが、私はいくつかのMethod.iを使用して解決は私のカメラアプリケーションでこの方法を使用していました。 私の方法:
public static Bitmap decodeSampledBitmapFromByte(Context context, byte[] bitmapBytes) {
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int reqWidth, reqHeight;
Point point = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(point);
reqWidth = point.x;
reqHeight = point.y;
} else {
reqWidth = display.getWidth();
reqHeight = display.getHeight();
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inMutable = true;
options.inBitmap = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Load & resize the image to be 1/inSampleSize dimensions
// Use when you do not want to scale the image with a inSampleSize that is a power of 2
options.inScaled = true;
options.inDensity = options.outWidth;
options.inTargetDensity = reqWidth * options.inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false; // If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
options.inPurgeable = true; // Tell to gc that whether it needs free memory, the Bitmap can be cleared
options.inInputShareable = true; // Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
return BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
int initialInSampleSize = computeInitialSampleSize(options, reqWidth, reqHeight);
int roundedInSampleSize;
if (initialInSampleSize <= 8) {
roundedInSampleSize = 1;
while (roundedInSampleSize < initialInSampleSize) {
// Shift one bit to left
roundedInSampleSize <<= 1;
}
} else {
roundedInSampleSize = (initialInSampleSize + 7)/8 * 8;
}
return roundedInSampleSize;
}
private static int computeInitialSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final double height = options.outHeight;
final double width = options.outWidth;
final long maxNumOfPixels = reqWidth * reqHeight;
final int minSideLength = Math.min(reqHeight, reqWidth);
int lowerBound = (maxNumOfPixels < 0) ? 1 :
(int) Math.ceil(Math.sqrt(width * height/maxNumOfPixels));
int upperBound = (minSideLength < 0) ? 128 :
(int) Math.min(Math.floor(width/minSideLength),
Math.floor(height/minSideLength));
if (upperBound < lowerBound) {
// return the larger one when there is no overlapping zone.
return lowerBound;
}
if (maxNumOfPixels < 0 && minSideLength < 0) {
return 1;
} else if (minSideLength < 0) {
return lowerBound;
} else {
return upperBound;
}
}
私はuが私の方法decodeSampledBitmapFromByteを(使用する必要があると思う)method.youは、あなたのコード内のすべてのメソッドを配置する必要があり、あなたの代わりに の。
このコードを使用すると、同じサイズになります。compress.iの後にLogCatを配置します。
は、それはあなたが...お楽しみに役立つことを願っています(:。
'quaiity'パラメータの値を小さくして圧縮してみます。 –