//imgdata 是 base64字符串
public static string SaveImage(string imgdata)
{
string result = "";
try
{
string imgPath = @"D:\Pic\Credit";
byte[] bytes = Convert.FromBase64String(imgdata.Replace("data:image/png;base64,", ""));
string filename = "ZQ" + ".png";//图片名
if (!Directory.Exists(imgPath))
{
Directory.CreateDirectory(imgPath);
}
string path = imgPath + "\\" + filename;
File.WriteAllBytes(path, bytes);
result = path;//获取保存后的路径
}
catch (Exception ee)
{
result = "";
}
return result;
}
C#base64转图片,然后保存到指定文件夹
最新推荐文章于 2024-05-21 20:47:04 发布