如何COM preSS拍摄的图像在Android的一个特定的大小? [英] How to Compress captured image to a specific size in Android?
问题描述
我用我的Android相机拍摄图像,但摄像头是800万像素,所以我避开4-5 MB的JPEG图像。所以,我想COM preSS下来,1 MB使用以下code。
I am capturing images using my Android camera, but the camera is 8 MP, so i get around 4-5 MB jpeg images. So, I tried to compress them down to 1 MB using the following code.
数据包含在图像的 JPEG 和 BAOS 为 ByteArrayOutputStream 键入
data contains the the image in jpeg and baos is of ByteArrayOutputStream type.
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 ;
}
这让我捕捉到了一些图片,但后几个图片,应用程序崩溃,错误日志内存不足。
。
任何一个可以请提供的PSS的JPEG较好地解决了COM $ P $。
It allows me to capture a few images but after a a couple of pics, the application crashes with error log Out of memory
.
Can any one please provide a better solution to compress a JPEG.
三江源
推荐答案
老问题,但我希望这有助于somebody.Adding此code开始循环将重置byteArrayOutputStream(BAOS):
Old question, but i hope this helps somebody.Adding this code to start of loop will reset byteArrayOutputStream(baos):
baos.reset();
这篇关于如何COM preSS拍摄的图像在Android的一个特定的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!