Jpeg images not proper in MAC

hi

i am saving a component to a jpeg 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 the image created becomes black. Can anyone tell me where the problem is or is there something else i should do while saving in mac

ps: i tried with following code too but same result

JPEGImageEncoder jpgencoder = JPEGCodec.createJPEGEncoder(out);

jpgencoder.encode(image);

[495 byte] By [Trushanta] at [2007-10-3 3:46:56]
# 1
Are you actually displaying it on the screen first? ie to determine that the image is actually not black, rather than the writer not working...
itchyscratchya at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...
# 2
ya i have image on the screen ...And the same writer works for Windows but not for Mac
Trushanta at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...
# 3

Odd. Have you tried cycling through all the available JPEG encoders, if there's more than one available, and writing a differently-named file from each, to see if it's just one failing or all of them?

Anything unusual about the image? What's the transfer type, color model, how are you obtaining it? For example using transparency might cause an issue, since it's not supported by JPEG.

itchyscratchya at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...
# 4

there is panel from which i create a buffered image and the buffered image is written ...the following code is what i use

BufferedImage image = (BufferedImage)_component.createImage( _component

.getWidth(), _component.getHeight() );

Graphics2D g = (Graphics2D)image.getGraphics();

if( g.getClipBounds() != null)

{

g.setClip( 0, 0, _component.getWidth(), _component.getHeight() );

}

_component.paint( g );

ImageIO.write( image, "jpg", file );

Trushanta at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...
# 5

Hi

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 );

Trushanta at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...
# 6
Then it would appear that the alpha channel is the issue. The casting to Image will make no difference at all - what is making the difference is that you're now saving an image with BGR format, ie with no alpha channel.
itchyscratchya at 2007-7-14 21:43:47 > top of Java-index,Desktop,Core GUI APIs...