Morteza Azizi
Morteza Azizi

Reputation: 479

How can I serialize a picture with Json-serializer?

How can I serialize a picture with Jason-serializer? I have a class that one property of this class is picture and for WCF Serilization I need to serialize this object with jason serializer, but it is not possible to do that.

Upvotes: 3

Views: 5202

Answers (2)

Karel Kral
Karel Kral

Reputation: 5486

Use this way of returning Stream (from 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;
}

Upvotes: 1

James Newton-King
James Newton-King

Reputation: 49062

Json.NET serializes byte arrays as base64 encoded text.

Upvotes: 3

Related Questions