This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Jpeg images not proper in MAC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jpeg images not proper in MAC" Watch "Jpeg images not proper in MAC" New topic

Jpeg images not proper in MAC

Trushant Patil

Joined: Apr 13, 2006
Posts: 7
i am saving a component to a jpeg image(converting component to buffered image) with the code line
ImageIO.write( image, "jpg", file );
this code works fine when component is saved in windows but in case of Mac OS X the image created gets a reddish tint . Can anyone tell me where the problem is or is there something else i should do while saving to jpeg images in mac

ps: i tried with following code too but same result
JPEGImageEncoder jpgencoder = JPEGCodec.createJPEGEncoder(out);
Trushant Patil

Joined: Apr 13, 2006
Posts: 7
I got the soultion. Instead of converting component to buffered image directly ... convert the component to image and then the image to buffered image. THis way the image get created correctly.

Image image = (Image)_component.createImage( _component.getWidth(),
_component.getHeight() );

//image converted to buffered image
BufferedImage bufferedImage = new BufferedImage ( _component.getWidth(),
_component.getHeight() , BufferedImage.TYPE_INT_BGR );

Graphics2D g = (Graphics2D)image.getGraphics();
_component.paint( g ); // draw the component on image
bufferedImage.createGraphics().drawImage( image, 0, 0, null);
ImageIO.write( bufferedImage, "jpg", file );
I agree. Here's the link:
subject: Jpeg images not proper in MAC
jQuery in Action, 3rd edition