Convert Image to Bytes and save in Xml

2019-03-05 23:16发布

问题:

I need to convert byte [] of an image to a format that can be saved in a xml. I tried to convert to a string but not worked. The xml file after 5 images saved was about the size of 50mb! I need to convert to a simpler format for this xml file can not be too heavy.

回答1:

Consider using a Base64 format - you lose some efficiency but the data will be encapsulated. For example

<image name="MyPhoto.jpg">WFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbm</image>

You can convert to Base64 using Convert.ToBase64



回答2:

Try compressing the byte array and hope the size will be smaller :). For example check :DeflateStream and hope the size will be reduced :)