Created
January 5, 2020 07:40
-
-
Save SumindaD/7a9064fd724bfdad6aa1bf56033ebba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Deserialize the unsigned xml document and retrieve the image | |
/// </summary> | |
/// <param name="xmlDocument">Unsigned XmlDocument</param> | |
/// <returns>Byte[] of the image</returns> | |
private static byte[] DeserializeXMLToImage(XmlDocument xmlDocument) | |
{ | |
StringWriter stringWriter = new StringWriter(); | |
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); | |
// Save Xml Document to Text Writter. | |
xmlDocument.WriteTo(xmlTextWriter); | |
UTF8Encoding encoding = new UTF8Encoding(); | |
// Convert Xml Document To Byte Array. | |
byte[] xmlDocumentBuffer = encoding.GetBytes(stringWriter.ToString()); | |
XmlSerializer mySerializer = new XmlSerializer(typeof(byte[])); | |
using (MemoryStream myFileStream = new MemoryStream(xmlDocumentBuffer)) | |
{ | |
return (byte[])mySerializer.Deserialize(myFileStream); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment