2012-03-03 69 views
3

如何用Jason-serializer序列化图片? 我有一个类,该类的一个属性是图片和WCF Serilization我需要用jason序列化程序序列化此对象,但不可能这样做。如何使用Json-serializer序列化图片?

+0

你使用'System.Drawing.Image'或'System.Drawing.Bitmap'或别的东西的这种方式? – 2014-02-07 13:35:11

回答

2

Json.NET将字节数组序列化为base64编码文本。

+2

你能详细说明一下'System.Drawing.Image'类型吗? – 2014-02-07 13:35:34

1

使用返回流(从WCF RAW programming

[OperationContract, WebGet] 
public Stream GetTestImage(Image image) 
{ 
    MemoryStream stream = new MemoryStream(); 
    image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); 
    stream.Position = 0; 
    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg"; 
    return stream; 
} 
相关问题