Hi, I want to save a BufferedImage to hard disk, as well as transmission across a network. Since it isn't serializable I want to shove it into a byte array using the ByteArrayOutputStream, and read it back as a ByteArrayInputStream. I tried simply using ImageIcon instead, but the file-size is very large when I serialize it.
Anyways, I was stuck and found some sample code a nice guy called Christen posted called "WrapBufferedImage". I wrote a
test harness around it and tested it but can't get it to work correctly. I now believe I understand it, and could write it from scratch myself, but I cannot see the flaw in it so feel it would be a waste of time until I can get this to work.
The test harness loads a picture into a JFrame, and saves this image as a byte array from a BufferedImage. Then you click the LoadBack button and it is supposed load the saved file back into a BufferedImage and display it. Unfortunately it only displays about 5% of the image, and the rest looks corrupt. I did a System.out.print of the byte array immediately after it was created and everything seems fine, but when I do the same as soon as it's loaded back, 95% of the array are zeroes.
So I can presume that either the array isn't saving correctly (though as I say, its being created fine), or the data is on the hard disk ok, it just isn't loading it back fully.
I'll post the code, the main class here is the WrapBufferedImage, whereas the test harness is MyFrame. If anyone could just paste this into their editor and have a quick look it'd be great. This has been frying my head for a week now.
Thanks in advance.