1 public static string ImgToBase64String(string filepath) 2 { 3 try 4 { 5 Bitmap bmp = new Bitmap(filepath); 6 MemoryStream ms = new MemoryStream(); 7 bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); 8 byte[] arr = new byte[ms.Length]; 9 ms.Position = 0; 10 ms.Read(arr, 0, (int)ms.Length); 11 ms.Close(); 12 string pic = Convert.ToBase64String(arr); 13 return pic; 14 15 } 16 catch 17 { 18 return false.ToString(); 19 } 20 }
时间: 2024-10-10 21:51:28