java.awt.image,为什么不是java.awt.image.BufferedImage中的序列化?
发布日期:2022-03-15 11:50:03 浏览次数:9 分类:技术文章

本文共 1341 字,大约阅读时间需要 4 分钟。

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().

转载地址:https://blog.csdn.net/weixin_34614004/article/details/118831219 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:小学生计划计算机使用计划,小学生计算机教学计划
下一篇:java 列表边传边显示,Java通过引用传递列表的问题

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.11.157.150]2022年05月12日 21时47分27秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

最新文章

项目知识点.Part1 2019-12-06 18:03:05
cocoaPods安装 2019-12-06 18:03:05
UITableView 2019-12-06 18:03:02
UITabBarController block 2019-12-06 18:03:03
数据解析 2019-12-06 18:03:03
网络部分(iOS) 2019-12-06 18:03:03
图片加载 第三方 KVO 2019-12-06 18:03:03
数据库 2019-12-06 18:03:04
数据持久化 2019-12-06 18:03:04
UI-UITextField UIButton 2019-12-06 18:03:01
UI-事件处理 2019-12-06 18:03:01
UI-设计模式 手势处理 2019-12-06 18:03:02
UIControl及其子类 2019-12-06 18:03:02
自己看的东西:UIWebView UIAlertController UIPickerView 2019-12-06 18:03:02
UIScrollView UIPageControl 2019-12-06 18:03:02
UINavigationController 2019-12-06 18:03:02
Objective-C---7---NSDate Protocol Category 2019-12-06 18:03:00
Objective-C---6---Block 2019-12-06 18:03:00
Objective-C---8---@property KVC 2019-12-06 18:03:00
Objective-C---9---内存管理 2019-12-06 18:03:00