• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization/Deserialization a picture

 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
reply
    Bookmark Topic Watch Topic
  • New Topic