Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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!