The moose likes I/O and Streams and the fly likes Serialization/Deserialization a picture Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Serialization/Deserialization a picture" Watch "Serialization/Deserialization a picture" New topic
Author

Serialization/Deserialization a picture

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 152

Hello,

I have a class called Face which has properties laid out. One of the things about the face is that it needs a picture assigned to it. I assign f to a File like I do with everything else as a int or string. I am able to serialize an array of files f[] and reading in the files with a for loop and using j as f[j] and using j as the file # in my images folder.


Now this works, and deserialization also works. My code for the Plan class which reads in all of the other information needed to create the plan. When I try to buffer the image using f[x].f it gives me an error saying

***NOTE*** This is not all the code, just the code that is used... If I need to add anything else I will if asked...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

If you look at the whole stack trace you will see what line of code threw that exception. That information is far, far, far more useful than just the description of the exception. So start looking there.

However I expect the message means what it says. Quite likely you have pointed the image-reader at a file which doesn't exist, or something like that.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 152

Paul Clapham wrote:If you look at the whole stack trace you will see what line of code threw that exception. That information is far, far, far more useful than just the description of the exception. So start looking there.

However I expect the message means what it says. Quite likely you have pointed the image-reader at a file which doesn't exist, or something like that.


Sorry, I edited my post...


It has to do where the image is being buffered. It just isn't being serialized... I could read the image into the Plan class, but I want the image to be associated with the faces themselves, there will probably be many pictures per face later on.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

I'm sorry, but I don't see anywhere that an image is being serialized.

Perhaps you thought that serializing a File object would also transfer the contents of that file? No. Here's what the documentation for java.io.File says:
An abstract representation of file and directory pathnames.

So that's what a File is. It's a path name. Nothing about the contents.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 152

Paul Clapham wrote:I'm sorry, but I don't see anywhere that an image is being serialized.

Perhaps you thought that serializing a File object would also transfer the contents of that file? No. Here's what the documentation for java.io.File says:
An abstract representation of file and directory pathnames.

So that's what a File is. It's a path name. Nothing about the contents.


Okay, I was kind of figuring that was the reason... So how would I go about doing this then? How can I bind a picture, or set of pictures into the class, or be able to get it to serialize?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

You want to serialize the data, not just the name of the file, right? So where in your code do you have some data which constitutes images?
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 152

Paul Clapham wrote:You want to serialize the data, not just the name of the file, right? So where in your code do you have some data which constitutes images?
I was just thinking that maybe I should buffer the image in, and then serialize it? Sorry I'm confused :). I guess I wasn't sure how to read the file in, but I guess using the buffered image it should serialize?
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 152

Okay so now I get




I looked it up and found that BufferedImage cannot be serialized(Damn wish I looked this up beforehand) and I was reading that you might have to convert it? I also read here that you can make a class to get the information of the picture and send it over?
http://www.rhinocerus.net/forum/lang-java-programmer/569808-what-options-serializing-bufferedimage.html

 
 
subject: Serialization/Deserialization a picture
 
Threads others viewed
How to know the number of items in your Seralization/Deserialization stream?
Adding graphics to JPanel using PopupMenu
Image Maps
Scrolling Components
Serialization/Deserialization of an Array of Objects
developer file tools