1

I have used this code to get Image into array of pixels.

  • convertTo2DWithoutUsingGetRGB method for reading image to pixel array
  • writeToFile method for pixel array to image

Now I would like to convert the array of pixels to Image. But when I convert it, I am losing image data.

  1. Initial Image size: 80Kb JPG
  2. Duplicate Image size: 71Kb JPG

I can clearly notice some difference between the both images, the Java produced image has some sort of white-noise.

I would like to reproduce the image without single pixel loss of data, how do I achieve in Java?

1
  • 1
    Perhaps you haven't searched well. In this site itself you can find solutions : question1 and question2. Commented Aug 1, 2013 at 7:48

1 Answer 1

1

The jpg file format uses a lossy compression algorithm which means that the files it generates will have slight differences from the original. 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. Use a lossless format instead, like PNG.

Sign up to request clarification or add additional context in comments.

6 Comments

It's looking bit different. Because the original image is JPG, why can't the same image be reproduced? It's like we can't copy original images using Java.
It's not java, it's the jpg file format. No image editing software can do what you're asking. If you want an exact copy you can use Files.copy
could be true. But if I want to just rotate the image and reproduce the copy of original image? or some other image operations?
That can be done without loss but it requires special knowledge of how the file format works internally and shuffling data around, not by reading the image as pixels. I think the standard libjpeg C library can do these operations, you can use jna or jni to call its functions from java
but not from Java? I tried with PNG format files, It's rotating and working fine. Though, why not with JPG or other file formats without loss of data?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.