Creating an image file from a Java Applet
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Wayless_Coyote
Posted On:   Friday, May 12, 2006 07:53 PM

I'm attempting to write out an image that I've created in the Applet Graphics window. I would like to be able to create the image by clipping a portion of the Graphics drawspace from inside or outside the visible window if possible. As an example, I've created a Hello World applet and drawn text and graphics on the Graphics object. I'd really appreciate seeing how this could be done. import java.applet.Applet; import java.awt.Graphics; public class HelloWorldApplet extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); g.drawLine(50, 25, 130, 25); } } I'd like to save the Graphics as an imag   More>>

I'm attempting to write out an image that I've created in the Applet Graphics window. I would like to be able to create the image by clipping a portion of the Graphics drawspace from inside or outside the visible window if possible.

As an example, I've created a Hello World applet and drawn text and graphics on the Graphics object. I'd really appreciate seeing how this could be done.



			
import java.applet.Applet;
import java.awt.Graphics;

public class HelloWorldApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
g.drawLine(50, 25, 130, 25);
}
}



I'd like to save the Graphics as an image. ( Any standard format should do. ) I've searched around and have been unable to find an example that bridges the full distance from the applet Graphics object and outputting the image file.

Thanks.    <<Less

Re: Creating an image file from a Java Applet

Posted By:   Robert_Lybarger  
Posted On:   Saturday, May 13, 2006 08:21 AM

This won't get you the full way there, but you need to invoke the "paint(Graphics g)" on an Image object instead of (or in addition to) the Applets display. From there, you should be able to get a binary representation of the image. (This is where you need more homework.) One important thing to note, though, is that an Applet is effectively sandboxed from doing anything to the client's filesystem (read or write)... you can "sign" the applet (not strictly required) and the client can modify the security policy of their JRE to allow filesystem writes (possibly only if an applet is signed by a given person), but this would have to be done by any person running the applet ... you could only provide instructions to the client/user, and then they may need to have administrator access to the JRE's security policy file.
About | Sitemap | Contact