[OpenJDK 2D-Dev] Why are java images type not serializable ?

Jim Graham james.graham at oracle.com
Tue Mar 10 21:18:53 UTC 2015

Just to clarify - what I've described here is not necessarily a hard and 
fast reason why it can't be done, but more the issues and considerations 
that go into why we haven't done it in the past.  That, and the fact 
that there isn't a big history of this being requested (insofar as I 
don't remember there being a bug/rfe filed against it).

It should certainly be filed as an RFE and we can discuss the technical 
hurdles and the workarounds in that context and gauge the level of 
interest from the community...


On 3/10/15 11:37 AM, Jim Graham wrote:
> Serializing images by content is generally wasteful in terms of the size
> of the data stream.
> For images loaded from a URL or file, presumably those can be reloaded
> by the application if it has a way to retrigger loading its resources (a
> common technique is to lazily load some images or have a central method
> for loading media - both of which are easy to trigger in the process of
> deserializing).
> For images that are generated on the fly, often those can be regenerated
> by the code, but it may not be as automatic as lazily reloading an image
> from its file/URL.
> One issue is that images may be loaded from a cache and multiple
> references stored throughout the program (particularly for images used
> as common UI elements).  I suppose that a well-written serialization
> mechanism may notice the repeated references and try to share the
> serialized forms, but I'm not entirely sure how that works or how that
> would impact serializing the images.
> There is also the issue that BufferedImages can be fully custom, which
> means that we have no idea how the pixels are stored or where they are
> stored.  The fact that ColorModel, SampleModel, and Raster are openly
> subclassable allows for such completely custom implementations.  We
> could not guarantee serializability of custom subclasses of any of
> those, unfortunately...
>              ...jim
> On 3/10/15 10:20 AM, Jean-François Savard wrote:
>> Hi,
>> I've realized java.awt.image.BufferedImage is not serializable.
>> After a couple of research, I've realized that each java image types
>> (correct me if I'm wrong) are not serializable at all.
>> I've then decided to do research without specifying java as language and
>> realized serialization of image is not present in most of the languages.
>> I've come to the conclusion that is simply because serializing an image
>> is illogical. When you load an image, it is because you already have the
>> resource stored somewhere (file or in-memory), so there is no point in
>> serializing it as the main utility of serialization is to store data
>> independent of the JVM, which is already the case for an image file. For
>> the case where the image is in-memory, it mean you already loaded the
>> ressource and have the byte array so it is better to simply serialize
>> that byte array.
>> Would you please confirm that my understanding is correct ?
>> Best regards.

More information about the 2d-dev mailing list