/// <summary>
/// 将传入的base64转化成png
/// </summary>
[HttpPost("ChangeBase64ToPng")]
[AllowAnonymous]
public async Task<string> ChangeBase64ToPng(DDARShopCodeKeyInput input)
{
string data = "a";
try
{
// 将Base64字符串转换为字节数组
byte[] imageBytes = Convert.FromBase64String(input.base64);
string outName = YitIdHelper.NextId().ToString();
string outputPath = @"C:\Users\admin\Desktop\qrcode\type"+ input.type + "\\"+ outName + ".png";
// 创建一个MemoryStream来存储字节数组
using (MemoryStream ms = new MemoryStream(imageBytes))
{
// 使用System.Drawing.Bitmap加载图像
using (Bitmap bitmap = new Bitmap(ms))
{
// 将图像保存为PNG文件
bitmap.Save(outputPath, ImageFormat.Png);
data = "图片已保存到:" + outputPath;
}
}
}
catch (Exception ex)
{
data = "转换并保存图片时出错:" + ex.Message;
}
return data;
} :本文最后更新于2023年12月07日,已经过了764天没有更新,若内容或图片失效,请留言反馈
.netcore实现base64转png并保存到指定文件夹
博主关闭了当前页面的评论