--
using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; namespace aliyun.utils { public static class ImageUtil { /// <summary> /// 将图片数据转换为Base64字符串,(默认是JPEG) /// </summary> public static string ToBase64(string filename) { ImageFormat imgf = System.Drawing.Imaging.ImageFormat.Jpeg; using (Image img = Image.FromFile(filename)) { using (MemoryStream memStream = new MemoryStream()) { img.Save(memStream, imgf); byte[] bytes = memStream.GetBuffer(); string base64 = Convert.ToBase64String(bytes); return base64; } } } } }
--