开发者

how to show image inside xml

I have a class containing:

[Serializable]
public class ClsStatus
{
     public byte[] Image { get; set; }
     public string Status { get; set; }
     public List<string> Servers { get; set; }
}

Now i am doing:

System.Drawing.Image image = null;
            byte[] imageBytes = null;

        // Create an image of the chart.
        using (MemoryStream s = new MemoryStream())
        {
            chart.ExportToImage(s, System.Drawing.Imaging.ImageFormat.Jpeg);
            image = System.Drawing.Image.FromStream(s);
            imageBytes = s.ToArray();
        }
        ClsStatus status = new ClsStatus();
        List<string> servers = new List<string>();
        servers.Add("Server1");
        servers.Add("Server2");
        servers.Add("Server2");

        status.Image = imageBytes;
        status.Status = "Up & Running";
        status.Servers = servers;

        //XML Serialization
        XmlDocument doc = new XmlDocument();
        XmlSerializer serializer = new XmlSerializer(status.GetType());
        MemoryStream stream = new MemoryStream();
        try
        {
            serializer.Serialize(stream, status);
            stream.Position = 0;
     开发者_如何学Python       doc.Load(stream);
            Response.ContentType = "text/xml";
            Response.Clear();
            Response.Write(doc.InnerXml);
        }
        catch
        {
            throw;
        }

My Desired out put and what i am getting fro the above code is here: http://i.stack.imgur.com/YgKgH.jpg

Is there any one who can help me in solving my issue?

Regards, Mohin


XML is pretty much a text-based format, which means you're not going to be able to "see the image" in your XML document.

The closest you can get is to encode the binary image data into a "text" string (typically through Base64 encoding) and then embed the string into the XML document. That's exactly what you're getting now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜