아마 정말 좋은 방법이 아니라 그 이상 근무 나 :
YuvImage image = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null); //create YuvImage instance with initial size
ByteArrayOutputStream bao = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), jpegQuality, bao);
외부에 설정된 값이 aspect
입니다. 이 값은 승수를 나타내며, 규모를 얼마나 줄입니까? aspect == 1
인 경우 동일한 해상도를 사용합니다. aspect == 2
경우 우리는 2 이미지 해상도를 나누는 등 경우에만 필요합니다 스케일링 경우 aspect != 1
if (aspect != 1) {
int newWidth = image.getWidth()/aspect;
int newHeight = image.getHeight()/aspect;
byte[] scaledBitmapData = bitmapToByteArray(createScaledBitmap(bao.toByteArray(), newWidth, newHeight));
bao = new ByteArrayOutputStream(scaledBitmapData.length);
bao.write(scaledBitmapData, 0 , scaledBitmapData.length);
image.compressToJpeg(new Rect(0, 0, newWidth, newHeight), jpegQuality, bao);
}
유틸리티 방법 :
public static Bitmap createScaledBitmap(byte[] bitmapAsData, int width, int height) {
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapAsData, 0, bitmapAsData.length);
return createScaledBitmap(bitmap, width, height);
}
public static Bitmap createScaledBitmap(Bitmap bitmap, int width, int height) {
return Bitmap.createScaledBitmap(bitmap, width, height, true);
}
public static byte[] bitmapToByteArray(Bitmap bitmap) {
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_QUALITY, blob);
return blob.toByteArray();
}
그리고 이것은 트릭을 할해야합니다.
크기 조정이 이클립스 또는 이미지 압축에 어떤 영향을 줍니까? 크기를 조정하기 위해 이클립스 또는 이미지 압축이 필요하지 않습니다. – Theolodis