简体   繁体   English

在Java中将像素数组转换为图像

[英]Converting Pixel Array to Image in Java

I have used this code to get Image into array of pixels. 我已使用此代码将Image转换为像素数组。

  • convertTo2DWithoutUsingGetRGB method for reading image to pixel array convertTo2DWithoutUsingGetRGB方法,用于将图像读取到像素数组
  • writeToFile method for pixel array to image 用于图像像素阵列的writeToFile方法

Now I would like to convert the array of pixels to Image. 现在,我想将像素数组转换为Image。 But when I convert it, I am losing image data. 但是当我转换它时,我正在丢失图像数据。

  1. Initial Image size: 80Kb JPG 初始图片大小:80Kb JPG
  2. Duplicate Image size: 71Kb JPG 图像大小重复:71Kb JPG

I can clearly notice some difference between the both images, the Java produced image has some sort of white-noise. 我可以清楚地注意到这两个图像之间存在一些差异,Java生成的图像具有某种白噪声。

I would like to reproduce the image without single pixel loss of data, how do I achieve in Java? 我想重现图像而不会丢失单个像素的数据,如何在Java中实现?

The jpg file format uses a lossy compression algorithm which means that the files it generates will have slight differences from the original. jpg文件格式使用有损压缩算法,这意味着它生成的文件将与原始文件略有不同。 You can change the quality setting to compress more or less but you can't save the with its original size without any modifications. 您可以更改质量设置以或多或少地进行压缩,但是如果不进行任何修改就无法保存其原始大小。

This is why jpg isn't recommended for image editing. 这就是为什么不建议将jpg用于图像编辑的原因。 Use a lossless format instead, like PNG. 请改用无损格式,例如PNG。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM