Hi Sven,

Component.createImage(width, height) does not take a snapshot of the
window as you seem to expect, it simply creates a brand new blank
image (cleared to the background color of the component) that is
compatible with the component so that you can use it as an offscreen
buffer for double buffering operations.

If you want to snapshot the screen then you can look into the Robot
interface (java.awt.Robot).  One drawback to capturing the results
from the screen is that your results will be affected by the depth
and color mode of the screen (8-bit with a palette that doesn't
contain the colors you want, grayscale, etc.).  Another drawback is
that your results might be obscured by overlapping windows.

You should check if Plotlib has a facility to make you an image
of the plot itself without involving your components.  That would be
the best way to create an image for writing out to disk.

If you do need to use the component to capture the rendering to an
image, then you would do better to create a BufferedImage of a known
type that is deep enough to contain all of the colors of your plot
and tell the component to draw into that image instead:

        BufferedImage img =
            new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
        Graphics g = img.getGraphics();
        plotcomponent.paint(g);
        g.dispose();

                                ...jim

--On Thursday, December 26, 2002 13:31:38 +0100 Sven Mielordt
<[EMAIL PROTECTED]> wrote:

> Dear J2D enthusiastics... 
> I'm a newbe here and yesterday downloaded the latest version of Java
> 1.4.1_01 to use the static class methods ImageIO.read() and
> ImageIO.write() to first read an image and give it out as a differently
> formatted file again:
> 
> File f = new  File("pic1.jpg"); 
> BufferedImage  bi =  ImageIO.read(f); 
> File  outfile = new File("pic2.png"); 
> ImageIO.write(bi, "png", outfile);
> 
> That works out properly as expected.
> 
> Now the problem arises: 
> I tried to get some simplified approach to mathematical funtion plots by
> using the Plotlib Toolkit from Bernhard Bablok (www.bablokb.de). It
> really works fine to plot something like the normal distribution or other
> funtions into a window on the screen. I then modified the
> FktTest.java-file a little bit to enable it to give a .jpg or .png-file
> from the displayed image. BUT:
> the following code fragment only gives a pic of the right size -but it
> only contains uniform grey pixels and nothing from that I can see on the
> screen.....
> 
> frame1.getContentPane().add(t); // original code by Bernhard Bablok, adds
> contents frame1.pack();  // original code by Bernhard Bablok
>       BufferedImage im2 = (BufferedImage)frame1.createImage(500,500); //
> my code       File outfile2  = new File("C:\\Java2D\\plotfile_CC25.png");
> // my code       ImageIO.write(im2, "png",  outfile2); // my code: only
> gray pixel file generated! frame1.show(); // original code by Bernhard
> Bablok: works properly
> 
> My questions: how can I create a .png or .jpg file from a JFrame oder
> other complex graphical "containers"? Is there a simple method to
> serialize the topically displayed window(s) and then convert the stream
> into a BuffereredImage and then to feed it into ImageIO.write()? I also
> append the GraphTest.java file; it is the test file I really used.
> 
> nice Xmas and thank you in advance .... Sven Mielordt
> 
> **************** 
> sender:  
> Sven Mielordt  
> Gro�beerenstra�e 81  
> D 10963 Berlin
> Germany
> Tel +49 30 2511999 
> [EMAIL PROTECTED] 
> *****************
> 
> _________________________________________________________________________
> _____ PREMIERE exklusiv bei WEB.DE: 3 Monate gratis + d-box-1 ab 1 Euro
> Online solange der Vorrat reicht! http://premiere.web.de/?mc=999937&lp=2

==========================================================================To 
unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to