Saving an image from an xml file to a jpg file

T

tshad

I have the following xml line in my xml file:

<binary xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"
format="jpeg">/9j/4AAQSkZJRgABAAE...</binary>

I need to take this image and write it to a jpeg file.

I am using "ds.ReadXml(memStream);" to get the data from the xml file. But
how do I write it to a jpg file that I can open in my graphics program or
web page.

I assume it is encoded using base64 encoding. How would I unencode it and
write it toa file?

Thanks,

Tom
 
M

Morten Wennevik [C# MVP]

Hi Tom,

If you are talking about transporting a dataset somewhere I would assume you
could get the image using DataSet.ReadXml() on the other end. However, if
you just want to grab the image data out of the xml use
Convert.FromBase64String(). Once you have a byte[] feed it to a MemoryStream
and use Image.FromStream() to get the picture. Or feed the byte[] to a
FileStream and save it to disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top