Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPEG Image problem

 
Abbie Morkel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wrote the below code to read pixels from an image and save the image. I again read the pixels from the save image but now the original image pixels and saved image pixels are not same. Can anyone tell me what is the problem and why does it happen. I have used the JAI library for this code. The same is the case when I use ImageIO.write();

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future, please UseCodeTags when posting code of any length. It's unnecessarily hard to read otherwise, making it less likely that people will bother to do so. I have done this for you here.

JPEG is not a lossless image format. That means that round-tripping an image through a read and write will not result in a pixel-perfect copy of the image. If you need that, consider using a lossless image format like PNG or TIFF.

One thing to try with your current code is to set the "quality" setting of the ImageEncodeParam parameter to 1.0; I'm not sure if that's the default, and it will increase the chances of the image not getting changed much (probably not to the point of pixelwise identity, though).

By the way, if you're not using JAI for manipulating the image, but just for reading and writing it, consider using the javax.imageio.ImageIO class with its read and write methods instead. JAI is dead for all practical purposes.
 
Abbie Morkel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am modifying the pixels (to store message) and want to save the modified pixels into image without loosing the pixel values and the image has to be jpg. But with the current approach i am not able to do that.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am modifying the pixels (to store message) and want to save the modified pixels into image without loosing the pixel values and the image has to be jpg. But with the current approach i am not able to do that.

Correct, for the reasons I mentioned above. So either the "pixel-perfect" requirement has got to give, or the "JPEG" requirement.

Please read the private message I sent you and act accordingly.
 
Abbie Morkel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am sorry for my stupid questions again.
Is there a way by which i can retain the pixel values and save as JPEG. I mean may be an algorithm which I could implement.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there isn't. Retaining pixel values and using JPEG are mutually exclusive.

Unless you fix your display name before your next post, your account will be closed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic