Java将图像转换为字节数组大小问题 [英] Java convert image to byte array size issues
本文介绍了Java将图像转换为字节数组大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的代码将图像转换为字节数组。
I have the below piece of code to convert an image to byte array.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
byte[] imageBytes = baos.toByteArray();
baos.close();
我面临的问题是图像的大小约为2.65MB。但是,imageBytes.length给了我一个超过5.5MB的值。有人能让我知道我哪里出错吗?
The issue that I am facing is that the size of the image is around 2.65MB. However, imageBytes.length is giving me a value more than 5.5MB. Can somebody let me know where I am going wrong?
推荐答案
PNG并不总是忠实的往返格式。它的压缩alghoritm会产生不同的结果。
PNG is not always a faithful round-trip format. Its compression alghoritm can yield different results.
编辑:同样适用于JPEG。
Same applies to JPEG.
这篇关于Java将图像转换为字节数组大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文