• 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

Using readObject() for BufferedImage

 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am trying to read a BufferedImage that I previously wrote to a File using writeObject() of the ObjectOutputStream class.
I am not getting any IOExceptions at runtime, but yet my BufferedImage is null after the object is read. I have doubled checked the filename, and it is correct. Can anyone tell me what I am missing here? Thanks!
Note: The NullPointerException is happening at the 'String s = image1.toString();' line



Barry:
Thxs for attempting to use the CODE tags.
For these thing to work, use [ ] and [/ ]
and not < >.
regds.
- satya

[This message has been edited by Madhav Lakkapragada (edited March 05, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it looks like there is not an object in the BufferedImage file (sure it isn't Image1.img???).
When you wrote out your BufferedImage did you check to make sure it got flushed so it really hit the file???
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am sure I flushed the stream, and yes I am also sure the filename extension is .im
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

then, do you keep your code in one dir and compiled code
.class files in another dir. I have seen people who have two
dir's src and classes.
Just guessing....
regds.
- satya
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barry Andrews:
Hi All,
I am trying to read a BufferedImage that I previously wrote to a File using writeObject() of the ObjectOutputStream class.
I am not getting any IOExceptions at runtime, but yet my BufferedImage is null after the object is read. I have doubled checked the filename, and it is correct. Can anyone tell me what I am missing here? Thanks!
Note: The NullPointerException is happening at the 'String s = image1.toString();' line



Barry:
Thxs for attempting to use the CODE tags.
For these thing to work, use [ ] and [/ ]
and not < >.
regds.
- satya

[This message has been edited by Madhav Lakkapragada (edited March 05, 2001).]


If you wan to save a BufferedImage object you need use a JPEGImageEncoder class. I don't know how you save your image before. The BufferedImage class is not Serializable. This is my example:
java.io.BufferedOutputStream out = new java.io.BufferedOutputStream(new FileOutputStream(new File("img.jpeg")));
com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(out);
encoder.encode(bufImage);
out.close();
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic