How do I get bytes out of a PNG file using C#, (Reason for this:I need to pass the PNG as a string in an XML file.)
+9
A:
System.Convert.ToBase64String(System.IO.File.ReadAllBytes(filePath));
ChaosPandion
2009-12-16 03:40:01
+1
A:
Alternatively, if you have the PNG file in memory:
- create a System.Drawing.Bitmap object out of it
- Serialize it to a memory stream using Bitmap.Save() (pass in PNG as the encoding)
- Use MemoryStream.GetBuffer() to retrieve the underlying byte array for the MS
- Use Convert.ToBase64String(byte[], 0, memoryStream.Position) to convert it to a base64 string
LorenVS
2009-12-16 03:46:33