Jase Jones

Greenhorn
+ Follow
since Apr 04, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jase Jones

I just threw the byte array into a basic class, saved the object to HDD, and it worked fine. Should have just done that from the start.

Thanks.
16 years ago
Good point, and this does seem wierd.

I changed the

read(byte[])
to
read(byte[], offset, length)

where the length should be 86409, but the return value from read(..) is 1020. This would definately seem to be the problem. Do you think its a problem in the save section?
But I don't see how it would be reading only 1020 bytes if I'm specifically supplying 86409?, but at the same time, I can't see any problem in the save section either?
16 years ago
complete guess, but maybe if you cast it.
16 years ago
Thanks for the advice,

I tagged on in WrapBufferedImage, but there wasn't a difference unfortunately.
16 years ago
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.

16 years ago