Naboo

Wednesday, January 14, 2009

(C#)Serialize image file into string

To convert an image file to Base64 string, use the code below. It's also easy to modify it to return in other string formats.

Image im = Image.FromFile(imagePath);
MemoryStream ms = new MemoryStream();
im.Save(ms, im.RawFormat);
byte[] array = ms.ToArray();
string result = Convert.ToBase64String(array);




0 Comments:

Post a Comment

<< Home