using System; using System.Collections.Generic; using System.IO; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShenTun.IcCard.Common { public class ImageHelper { public static string ToBase64(Bitmap bmp, System.Drawing.Imaging.ImageFormat format) { try { MemoryStream ms = new MemoryStream(); bmp.Save(ms, format); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); String strbaser64 = Convert.ToBase64String(arr); return strbaser64; } catch (Exception ex) { throw new Exception("ImgToBase64String 转换失败 Exception:" + ex.Message); } } } }