ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 类库 ``` //图片转为base64编码的字符串 public static string BitMapToBase64String(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; } } ``` # 用法 ``` string b64= QRCode.GenerateBase64(@"\images\cross.png", "http://www.baidu.com"); Response.Write("<img src='data:image/png;base64," + b64+"'>");//data:image/jpeg;base64,base64编码的jpeg图片数据 ```