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

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

问题描述

我有一些要序列化然后反序列化的缓冲图像。
例如,我有一个arrayList,其中充满了缓冲的图像,这些图像经过迭代并写入
ObjectOutputStream

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?

推荐答案

编辑:问题已解决

最终转换缓冲的图像到字节数组,然后将它们卡在h映射并使用一些哈希码作为键。
然后序列化哈希图。
一切都很好。

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天全站免登陆