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

Discussion in 'Java' started by F C, Sep 30, 2003.

  1. F C

    F C Guest

    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();
    }
    F C, Sep 30, 2003
    #1
    1. Advertising

  2. 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...
    Knute Johnson, Sep 30, 2003
    #2
    1. Advertising

  3. F C

    F C Guest

    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
    F C, Oct 1, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick
    Replies:
    1
    Views:
    717
  2. Davidski
    Replies:
    0
    Views:
    3,861
    Davidski
    Nov 5, 2004
  3. Robert Metzger
    Replies:
    1
    Views:
    4,199
    Andrey Kuznetsov
    Jan 14, 2005
  4. Replies:
    2
    Views:
    8,023
    Carfield Yim
    Feb 20, 2005
  5. Replies:
    3
    Views:
    994
    Andrew Thompson
    Jan 10, 2007
Loading...

Share This Page