我有一个图像类,根据图像嵌入或不嵌入的情况,必须(有时)序列化/反序列化。带图像的数据合同序列化/序列化
[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();
}
...
,但是当我这样做,我得到一个序列化错误。 那我该怎么办? 我不会将图像转换为字节[]或其他。我选择Datacontract序列化我认为它可以serilize图像。 谢谢
哪里它说的DataContractSerializer可以序列化图像? –
那么datacontract串行器的优点是什么? – Luca
比什么优势? –