Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Using readObject() for BufferedImage  RSS feed

 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!