如何在C#中将图像转换为base64字符串?
例如,我有图像的路径C:/image/1.gif并想data:image/gif;base64,/9j/4AAQSkZJRgABAgEAYABgAAD..返回。
C:/image/1.gif
data:image/gif;base64,/9j/4AAQSkZJRgABAgEAYABgAAD..
尝试这个
using (Image image = Image.FromFile(Path)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); return base64String; } }