Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > javax.imageio.ImageIO.write() failed to find a png writer

Reply
Thread Tools

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

 
 
F C
Guest
Posts: n/a
 
      09-30-2003
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();
}
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      09-30-2003
F C wrote:
> 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.

--

Knute Johnson
email s/nospam/knute/
Molon labe...

 
Reply With Quote
 
 
 
 
F C
Guest
Posts: n/a
 
      10-01-2003
Knute Johnson <> wrote in message news:<>...

>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ANN: PNG image CAPTCHA with PNG canvas available (SkimpyGimpy) aaronwmail-usenet@yahoo.com Python 0 04-18-2007 07:33 PM
Problems with Cdrom and DVD writer and CD writer Combo reachinout Computer Support 1 09-20-2004 10:02 PM
Isn't DataGrid.Render(writer) supposed to automatically call RenderBeginTag(writer) and RenderEndTag(writer)? Henri ASP .Net Building Controls 1 07-13-2004 10:27 PM
CD writer and Dvd writer problem Gareth not NLL or anybody else. Computer Support 3 04-28-2004 12:41 PM
Replacing CD writer with DVD writer zebu Computer Support 5 04-12-2004 03:04 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57