Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2777

Re: jpanel export as pbm

From "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Subject Re: jpanel export as pbm
Message-ID <7b52d0e6b89a3@uwe> (permalink)
Newsgroups comp.lang.java.gui
References <473dc83a$0$24398$5fc3050@news.tiscali.nl>
Date 2011-04-27 15:41 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Bruintje Beer wrote:
..
>I have a question. 

Do you?  I don't see it.  A question would usually be followed by 
a question mark '?'.  The question marks denotes a question.  It
also helps the reader to quickly identify the question in usenet posts.
I encourage the use of one (approrpriately applied) question mark in
each post.

>...I have a JPanel with some custom drawings on it like 
>rectangles, circles etc. Now I want
>to export The Jpanel as a PBM file. 

Why PBM?  I had to google to find that was some sort
of monochrome (ick) image format.

Why not save as PNG?

>...I have no idea how to do this.
>
>Maybe someone can point me to some url where I can read how to do it.

Here are two methods from the WebStartFrame I am developing.
They might get you started..

  public static BufferedImage getScreenShot(
    Component component) {

    BufferedImage image = new BufferedImage(
      component.getWidth(),
      component.getHeight(),
      BufferedImage.TYPE_INT_RGB
      );
    // call the Component's paint method, using
    // the Graphics object of the image.
    component.paint( image.getGraphics() );
    return image;
  }



  public void saveScreenShot(BufferedImage image) {
    getLogger().log(Level.FINEST, "Default saveScreenShot");
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      // write the image as a PNG
      ImageIO.write(
        image,
        "png",
        baos);
      byte[] bytes = baos.toByteArray();
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

      saveFileDialog(null, null, bais, null);
    } catch(Exception e) {
      handleError(e);
    }
  }

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200711/1

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

jpanel export as pbm file "Bruintje Beer" <bruintje.beer@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000
  Re: jpanel export as pbm "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:41 +0000

csiph-web