aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JPEG Image problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JPEG Image problem" Watch "JPEG Image problem" New topic
Author

JPEG Image problem

Abbie Morkel
Greenhorn

Joined: Apr 14, 2010
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
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

Joined: Apr 14, 2010
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
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

Joined: Apr 14, 2010
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPEG Image problem