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