Why aren't java.awt.image.BufferedImage serializable?

I am trying to serialize a BufferedImage in Java, but running my program, I got a NotSerializableException .

Looking at the BufferedImage class, I noticed that it does not implement Serializable .

Why doesn't BufferedImage implement Serializable ?

+6
source share
1 answer

I think you just discovered a missing feature.

  • Does it make sense to have BufferedImage implements Serializable ? In my opinion, this is so. Especially if BufferedImage not loaded from a file, but created and drawn. But even if it is from a file that takes care of where the material comes from, if I want to exchange it between virtual machines via RMI or similar?
  • Is there anything in BufferedImage that gives a strong technical reason against BufferedImage implements Serializable ? I looked at the source code and I don't think so.

I checked if the error database already contains an entry for this, and I could not find anything related. So, this is your chance to contribute and suggest a feature request through the error database. http://bugs.java.com/bugdatabase/

As a workaround, you can take a look at the implementation of readObject() and writeObject() in the javax.swing.ImageIcon class. ImageIcon Serializable . Perhaps you can wrap the BufferedImage in ImageIcon for your use case or otherwise provide the logic from ImageIcon.readObject() / ImageIcon.writeObject() .

+4
source

Source: https://habr.com/ru/post/983556/


All Articles