• Post Reply Bookmark Topic Watch Topic
  • New Topic

serilizing BufferedImage  RSS feed

 
Jigar Gosar
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i have an array of buffered image.
unfortunately the are not serializable (can someone tell me why?).
so someone please tell me some quick and clean way to save and load a BufferedImage class. I know it is not possible directly, but some short might help me a lot...
thanks.
regards,
JigarGosar
[ February 06, 2004: Message edited by: Jigar Gosar ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
unfortunately the are not serializable (can someone tell me why?).
Because there are already other formats designed to store image data, such as JPG and PNG. Serialization would probably be slower, consume more memory, and would result in files that could only be used by other Java programs. By using a standard image format, other applications can process the files too.
so someone please tell me some quick and clean way to save and load a BufferedImage class. I know it is not possible directly, but some short might help me a lot...
To load:

To save:

More examples of the javax.imageio clsses can be found here.
 
Jigar Gosar
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i have an array of buffered image.

thanks for the answer, but i have an array and i dont want to think up names for each image, also i want to save this array and load it in my program as a single file...
please help,
thanks,
regards,
Jigar Gosar.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For names, it should be easy enough to take some base name, and append a number. E.g.
somename_img_0.jpg
somename_img_1.jpg
somename_img_2.jpg
somename_img_3.jpg
...
If you really want everything in one file - well, you could write everything to a ZipOutputStream I suppose, and read it with a ZipInputStream.
As far as I can see, Java simply does not provide serializable Image classes, and the simplest solution I can see is to use standard image file formats.
 
Jigar Gosar
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is getting too complicated.
well i am now simply storing the rgb values of buffered image in a file..
thanks anyways.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!