java.awt.image,为什么不是java.awt.image.BufferedImage中的序列化?

I'm trying to serialize a BufferedImage in Java, but running my program I received a NotSerializableException.

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

Why doesn't BufferedImage implement Serializable?

解决方案

I think you've just discovered a missing feature.

Does it make sense to have BufferedImage implements Serializable? In my opinion it does. Especially if the BufferedImage was not loaded from a file, but created and drawn upon. But even if it's from a file, who cares where the stuff comes from if I want to exchange it between VMs via RMI or similar?

Is there anything in BufferedImage that provides a strong technical reason against BufferedImage implements Serializable? I browsed the source code, and I don't think so.

I checked whether the bug database already contains an entry for that, and I couldn't find anything related. So, this is your chance to make your contribution and suggest a feature request via the bug database. http://bugs.java.com/bugdatabase/

As a workaround, you might want to look at the implementation of readObject() and writeObject() in class javax.swing.ImageIcon. ImageIcon is Serializable. Maybe you can wrap the BufferedImage in an ImageIcon for your use case, or somehow otherwise provide the logic from ImageIcon.readObject() / ImageIcon.writeObject().

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值