Posted By:
Eli_Morris
Posted On:
Sunday, March 10, 2002 07:16 PM
For converting an image to a gif, first get a copy of the GifEncoder class from Acme.com--
http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html
Here is some code that I used to create an image using the GifEncoder class.
try {
// Create an unshown frame
frame = new Frame();
frame.addNotify();
// Get a graphics region, using the Frame
Image image = frame.createImage(1100, 1600);
g = image.getGraphics();
// Draw "Hello World!" to the off screen graphics context
g.setFont(new Font("Serif", Font.ITALIC, 48));
g.drawString("Hello World!", 10, 50);
GifEncoder encoder = new GifEncoder(image, outputFile);
encoder.encode();
} finally {
// Clean up resources
if (g != null) g.dispose();
if (frame != null) frame.removeNotify();
}