问题描述
在Android上,我该如何保存图像文件为JPEG时30%的质量?
On Android, how do I save an image file as a JPEG at 30% quality?
在标准的Java,我会用的ImageIO
读取图像作为的BufferedImage
,然后保存为一个使用 IIOImage的
例如JPEG文件:<一href="http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-com$p$pssion-quality-when-saving-images-in-java">http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-com$p$pssion-quality-when-saving-images-in-java.它的出现,然而,Android的缺乏的javax.imageio
包。
In standard Java, I would use ImageIO
to read the image as a BufferedImage
, then save it as a JPEG file using an IIOImage
instance: http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-compression-quality-when-saving-images-in-java. It appears, however, that Android lacks the javax.imageio
package.
推荐答案
您可以通过调用COM preSS并设置第二个参数存储为JPEG格式的位图:
You can store your bitmap in the JPEG format by calling compress and setting the second parameter:
Bitmap bm2 = createBitmap();
OutputStream stream = new FileOutputStream("/sdcard/test.jpg");
/* Write bitmap to file using JPEG and 80% quality hint for JPEG. */
bm2.compress(CompressFormat.JPEG, 80, stream);
这篇关于如何保存在Android上的JPEG图像与自定义质量级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!