序列化/反序列化缓冲图像 [英] Serializing/Deserializing buffered images

查看:68
本文介绍了序列化/反序列化缓冲图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组缓冲图像,我想对其进行序列化然后反序列化.例如,我有一个充满缓冲图像的 arrayList,这些图像被迭代并写入对象输出流

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?

此外,一旦图像被重新序列化,它们就会被重绘为 JLabel,我如何知道每个 JLabel 哪个图像是正确的?

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?

推荐答案

问题已解决

最终将缓冲的图像转换为字节数组,然后将它们放入哈希映射中,并使用一些哈希代码作为键.然后序列化哈希映射.一切都很好.

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.

这篇关于序列化/反序列化缓冲图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆