Serializing/Deserializing buffered images

爱⌒轻易说出口 提交于 2019-12-13 03:16:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!