Saving an image from an xml file to a jpg file

  • Thread starter Thread starter tshad
  • Start date Start date
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
 
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.
 
Back
Top