Hi i had an idea to load image files into an image[] and then save the image[] by useing the ObjectOutputStream wraped in the FileOutputStrem but there is a problem, the image class does not implement the Serializable interface, if some one knows of a work around for me please help
here follows my code
/**************************************************
* CODED BY HENNIE LOUW (LIZZERD) ON 18 JULY 2001 *
**************************************************/
/************************************************************************
* What I attemted to do in this class was to make a utility that loads *
* gif Images into a Image[] and then saves it into a file useing the *
* ObejctOutputSteam into the file of your choice eg [ ball.ani ] *
************************************************************************/
import java.io.*;
import java.awt.*;
import java.applet.*;
public class SaveAnimation extends Component implements Serializable
{
Image[] loadedImage;
ImageWritingClass imageAnimation;
/*****************************************************************************
* This constructor creates a complex data type that has a complex data type *
* with the Image[] in it *
*****************************************************************************/
public SaveAnimation(
String fileName, int totalNumber, String ext)
{
imageAnimation = new ImageWritingClass(fileName, totalNumber, ext);
}
/******************************************************************************
* this Constructor was medw to be use when you make an object in your
applet *
* to call the loudFromFile() method *
******************************************************************************/
public SaveAnimation(){ }
/************************************************************************
* This method Saves the image[] into the file *
* NOTE you need to specify the filename and extension *
************************************************************************/
public void saveToFile(String saveFileName, String ext)
{
try
{
FileOutputStream fileOutput = new FileOutputStream(saveFileName+"."+ext);
try
{
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
objectOutput.writeObject(imageAnimation);
objectOutput.flush();
fileOutput.close();
}
catch(IOException e){ System.out.println(e.toString()); }
}
catch(FileNotFoundException e){ System.out.println(e.toString()); }
}//end of saveToFile
/********************************************************************
* this Method reads the saved image[] file and retruns a image[] *
* NOTE you need to specify the filename and extension *
********************************************************************/
public Image[] loadFromFile(String loadFileName, String ext)
{
try
{
FileInputStream fileInput = new FileInputStream(loadFileName+"."+ext);
try
{
ObjectInputStream objectInput= new ObjectInputStream(fileInput);
try
{
imageAnimation = (ImageWritingClass)(objectInput.readObject());
}catch(ClassNotFoundException e){ System.out.println(e); }
fileInput.close();
}
catch(IOException e){System.out.println(e);}
}
catch(FileNotFoundException e){System.out.println(e);}
loadedImage = imageAnimation.getImage();
return(loadedImage);
}//end of loadAnimation
}//end of class SaveAnimation
/**************************************************
* CODED BY HENNIE LOUW (LIZZERD) ON 18 JULY 2001 *
**************************************************/
import java.awt.*;
import java.io.*;
public class ImageWritingClass extends Component implements Serializable
{
/**********************************************************************************
* The constructor loads all the frames witch iamge files into a image array *
* The file name is passed to the construtor and the total number of frames, *
* the differnt gif's that are loaded sould all have the same filename with the *
* frame number at the end starting at one *
**********************************************************************************/
Image[] imageAnimation;
MediaTracker frameTracker = new MediaTracker(this);
Toolkit imageTool;
public ImageWritingClass(String fileName, int totalNumber, String ext)
{
try
{
imageTool = getToolkit();
imageAnimation = new Image[totalNumber];
for(int frameNumber = 1; frameNumber < totalNumber; frameNumber++)
{
imageAnimation[frameNumber - 1] = imageTool.getImage(fileName+frameNumber+"."+ext);
frameTracker.addImage(imageAnimation[frameNumber -1], 0);
}
frameTracker.waitForID(0);
}catch(InterruptedException e){ System.out.println(e); }
}// End of SaveAnimation
public Image[] getImage()
{
return(imageAnimation);
}
}//end of class