【发布时间】:2016-06-10 20:32:16
【问题描述】:
我有一个类,其图像必须(有时)根据图像是否嵌入的事实进行序列化/反序列化。
[DataContract(IsReference = true)]
public class Data
{
[DataContract(IsReference = true)]
public class MyImage
{
[DataMember]
int WidthStorage
[DataMember]
int HeightStorage;
[DataMember]
public string strImageLocation;
[DataMember]
public Image ImageEmbedded = new Image();<----- not working null
public bool GetImage(Image image, int width, int height)
{
...
}
public void SetImageFSlocation(string _strImageLocation, int _widthStorage, int _heightStorage)
{
...
}
public void SetImageEmbedded(string strPathFilename, int _widthStorage, int _heightStorage)
{
...
}
}
所以问题是尽管放了
public Image ImageEmbedded = new Image();
ImageEmbedded 始终为空。 所以我把它放在像
这样的构造函数中[DataContract(IsReference = true)]
public class MyImage
{
public MyImage()
{
ImageEmbedded = new Image();
}
...
但是当我这样做时,我得到一个序列化错误。 那我该怎么办? 我不会将 Image 转换为 byte[] 或其他。我选择了 Datacontract 序列化,因为我认为它可以序列化图像。 谢谢
【问题讨论】:
-
哪里说DataContractSerializer可以序列化一个Image?
-
那么数据契约序列化器有什么优势???
-
比什么有优势?
-
超过标准的 MS 二进制序列化
-
与 .NET 以外的其他系统的兼容性。二进制序列化几乎是 .NET 特定的,不太可能可靠地与其他任何东西一起使用。
标签: c# wpf image datacontractserializer