在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public static string ImgToBase64String(Bitmap bmp) { try { MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); return Convert.ToBase64String(arr); } catch (Exception ex) { return null; } } 只需要传入一个Bitmap对象,亲测可用哈。返回给前台时,将转换成base64的码前面加上 data:image/png;base64, 例如: Bitmap bt; string base64Img = ImgToBase64String(bt); this.Image1.ImageUrl = "data:image/png;base64," + base64Img;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论