Android 카메라를 사용하여 이미지를 캡처하고 있지만 카메라가 8MP이므로 약 4-5MB의 JPEG 이미지를 얻을 수 있습니다. 따라서 다음 코드를 사용하여 1MB로 압축하려고했습니다.Android에서 캡처 한 이미지를 특정 크기로 압축하는 방법은 무엇입니까?
데이터은 JPEG 및baos가있는 ByteArrayOutputStream 형인의 이미지를 포함한다.
while (data.length > 1 * 1024 * 1024)
{
System.gc();
Log.e(TAG,"Data size "+ (data.length/1024));
bitmapData.compress(CompressFormat.JPEG, compressionRatio, baos);
data = baos.toByteArray();
Log.e(TAG,"Data size "+ (data.length/1024));
compressionRatio -= 5 ;
}
그것은 나에게 몇 가지 이미지를 캡처하지만 사진의 몇 후 수, 오류 로그 Out of memory
와 응용 프로그램이 충돌합니다. JPEG 압축에 더 나은 솔루션을 제공 할 수 있습니까?
감사합니다
http://stackoverflow.com/questions/4943016/android-how-을 이미지를 압축 또는 축소 할 수 있습니다. – Raghunandan
http://stackoverflow.com/questions/6265008/how-to-reduce-large-image-size-to-thumbnail-size-in-android – juned
그냥 FileOutputStream을 사용하십시오. out = new FileOutputStream (file); \t \t \t \t \t bm.compress (Bitmap.CompressFormat.JPEG, 90, out); –