URGENT: Conversion of Image object to gif/jpeg
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   anu_pama
Posted On:   Friday, March 8, 2002 10:22 PM


How to convert an Image object to a gif/jpeg file so that we can display the image file in a Browser by using the the IMG tag?


Thanks


Anupama

Re: URGENT: Conversion of Image object to gif/jpeg

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();
}


About | Sitemap | Contact