0

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?

BMac
  • 87
  • 2
  • 9
  • From what I know (which probably isn't much :P), I don't think what you are trying to do is possible. I don't think PNG has a concept of sub images and even if it does, the way you are writing the images wouldn't produce the effect you're after. Essentially, you're writing the "header/image data/footer" to the file. `ImageIO` is reading the "header/image data/footer" and going, that's it, cause that how that image format works. – MadProgrammer Aug 23 '12 at 01:20
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Aug 23 '12 at 01:44

1 Answers1

0

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.

BMac
  • 87
  • 2
  • 9
  • Thanks in advance ..!!! Can you provide function or any API for that : 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... – Jay Thakkar Jan 20 '14 at 04:43