简体   繁体   English

在WPF中序列化BitmapImage

[英]Serializing BitmapImage in WPF

I'm trying to serialize a custom class, however I get a error saying System.Windows.Media.Imaging.BitmapImage is not marked as serializable. 我正在尝试序列化自定义类,但是出现错误,提示System.Windows.Media.Imaging.BitmapImage未标记为可序列化。 I understand that I will need to convert it a byte array or something in order to serialize it, but I'm not sure how to approach this. 我知道我需要将其转换为字节数组或某种东西才能序列化,但是我不确定如何处理。

I've found this question: Serializing a WPF Image but don't know how to adapt it for my use. 我发现了这个问题: 序列化WPF图像,但不知道如何适应我的使用。 Could someone point me in the right direction and possibly link some material to read up on when dealing with serialization in WPF. 有人可以向我指出正确的方向,并可能在WPF中处理序列化时链接一些材料以供阅读。

一种方法是将ImageSource传递给WriteableBitmap的构造函数,然后使用WriteableBitmap的Pixels属性获取像素数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM