问题
I have a collection of buffered images that I want to serialize and then deserialize. For example I have an arrayList full of buffered images which are iterated through and written to a ObjectOutputStream
for (BufferedImages i : images{
ImageIO.write(i,"png",ImageIO.createImageOutputStream(output));
}
When I go to re-serialize the images, I tried to use
BufferedImage image =ImageIO.read(ImageIO.createImageInputStream(input));
but it only reads in one image.
Whats the correct way to re-serialize a collection of buffered images stored within the same serialized file?
Also once the images have been re-serialized they get redrawn to a JLabel, How do I know which image is the correct one for each JLabel?
回答1:
Edit:Problem solved
Ended up converting the buffered images to a byte array then stuck them in a hash map and used some hash codes as keys. Then serialized the hash map. All good.
来源:https://stackoverflow.com/questions/12083412/serializing-deserializing-buffered-images