dcsimg
write .gif to disc
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   walter_dubiansky
Posted On:   Tuesday, January 14, 2003 11:01 AM

I simply would like to write an Image Object to disc as a .gif file from a Java application. Here's how I'm creating the Image Object: ImageFilter filter = new EFilter(); ImageProducer producer = new FilteredImageSource(image.getSource(), filter); Image resultImage = Toolkit.getDefaultToolkit().createImage(producer); I can copy a .gif file on disc with the following code: FileInputStream SourceFile = new FileInputStream(sourceFilePath); FileOutputStream DestinationFile = new FileOutputStream(destinationFilePath); byte readFromFile[] = new byte[SourceFile.available()]; SourceFile.read(readFromFile); DestinationFile.write(readFromFile);    More>>

I simply would like to write an Image Object to disc as a .gif file from a Java application. Here's how I'm creating the Image Object:

			
ImageFilter filter = new EFilter();
ImageProducer producer = new FilteredImageSource(image.getSource(), filter);
Image resultImage = Toolkit.getDefaultToolkit().createImage(producer);


I can copy a .gif file on disc with the following code:

			
FileInputStream SourceFile = new FileInputStream(sourceFilePath);
FileOutputStream DestinationFile = new FileOutputStream(destinationFilePath);
byte readFromFile[] = new byte[SourceFile.available()];
SourceFile.read(readFromFile);
DestinationFile.write(readFromFile);

Which leads me to believe that if I can convert the Image Object to a byte array then I can write it to disc using the code above without corrupting any data, but I don't know how to convert the Image Object to a byte array.


Or, if I knew how to convert the Image to a BufferedImage I might be able to do something like:

			
ImageIO.write(myBufferedImage, ".gif", file);

But I don't know how to convert or if ImageIO has an ImageWriter that supports the gif format. Must stay within J2SE 141 API.


Anyone?

   <<Less
About | Sitemap | Contact