I have a Serializable object which is supposed to hold a java.awt.Image as its member. How should I go about serializing it? (Edited from a not so clear first version, sorry.)
A:
None that I know of. I believe you need to write your own serializer for it to basically save out the width, height and pixel values... Or write it out to the stream as a PNG or something
tim_yates
2008-09-26 14:55:47
+4
A:
ImageIcon implements Serializable and it can be used to wrap an Image class
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html
pfranza
2008-09-26 14:58:19
I could kiss you. Thanks!
Epaga
2008-09-26 15:02:09
you're most welcome*kissing not required
pfranza
2008-09-26 15:06:03
Just be aware:Warning: Serialized objects of this class will not be compatible with future Swing releases.
McDowell
2008-09-26 15:06:30
+1
A:
javax.swing.ImageIcon, as a part of Swing, does not guarantee to have compatible serialised form between versions. However, you can cheat and look at its readObject and writeObject code - find width and height, grab the pixels with PixelGrabber. I'm not entirely sure that covers the colour model correctly. The obvious alternative is to write a real image format with javax.imageio.
Tom Hawtin - tackline
2008-09-26 15:14:09