javax.imageio.ImageIO.write() failed to find a png writer

F

F C

Good morning

I am trying to save a awt Gui component into a file with the png
format,
I use java 1.4.0 under Solaris:
I only an empty file output for my Canvas

I used the excellent java image faq provided by Marco Schmidt
http://www.geocities.com/marcoschmidt.geo/index.html to guide me.

in the following code, the method mageIO.write() returns false
when I try to get a png file output (I only got an empty output file)
but the same works fine to get a jpeg file (nice canvas output).

Does someone has an idea why no appropriate writer is found for png
file ?

On the same computer, the Screenshot.java source works fine (from
previous Marco Schmidt url 'take a screenshot and save it to a Png
file using javax.imageio')

Thank you for your help
Ps: please reply only in the newsgroup not by email
F

Rectangle rect = getCanvas().getBounds();
Image fileImage = getCanvas().createImage(rect.width, rect.height);

Graphics g = fileImage.getGraphics();

getCanvas().paint( fileImage.getGraphics() );

try {
boolean ret = ImageIO.write((RenderedImage) fileImage, "png", new
File("map.png"));
System.out.println(ret);
} catch (IOException e1) {
/ TODO Auto-generated catch block
e1.printStackTrace();
} finally{
g.dispose();
}
 
K

Knute Johnson

F said:
Good morning

I am trying to save a awt Gui component into a file with the png
format,
I use java 1.4.0 under Solaris:
I only an empty file output for my Canvas

I used the excellent java image faq provided by Marco Schmidt
http://www.geocities.com/marcoschmidt.geo/index.html to guide me.

in the following code, the method mageIO.write() returns false
when I try to get a png file output (I only got an empty output file)
but the same works fine to get a jpeg file (nice canvas output).

Does someone has an idea why no appropriate writer is found for png
file ?

On the same computer, the Screenshot.java source works fine (from
previous Marco Schmidt url 'take a screenshot and save it to a Png
file using javax.imageio')

Thank you for your help
Ps: please reply only in the newsgroup not by email
F

Rectangle rect = getCanvas().getBounds();
Image fileImage = getCanvas().createImage(rect.width, rect.height);

Graphics g = fileImage.getGraphics();

getCanvas().paint( fileImage.getGraphics() );

try {
boolean ret = ImageIO.write((RenderedImage) fileImage, "png", new
File("map.png"));
System.out.println(ret);
} catch (IOException e1) {
/ TODO Auto-generated catch block
e1.printStackTrace();
} finally{
g.dispose();
}

I'm not sure why it doesn't throw and exception. Image does not support
the RenderedImage interface. You need to use a BufferedImage.
 
F

F C

Knute Johnson said:
I'm not sure why it doesn't throw and exception. Image does not support
the RenderedImage interface. You need to use a BufferedImage.

It works :)
Thank you for your help
F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top