Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2007

Tip: Looking for answers? Try searching our database.

jpanel export as pbm file

Thread view: 
Bruintje Beer - 16 Nov 2007 16:41 GMT
Hi,

I have a question. 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. I have no idea how to do this.

Maybe someone can point me to some url where I can read how to do it.

thanks a lot

Johan
Andrew Thompson - 17 Nov 2007 00:43 GMT
...
>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);
   }
 }

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.