public string Base64ToImage(string base64Str, string path, string imgName)
{
//图片格式
string hz = base64Str.Split(',')[0].Split(';')[0].Split('/')[1];
string[] str = base64Str.Split(',');
byte[] imageBytes = Convert.FromBase64String(str[1]);
//写入内存流
MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
memoryStream.Write(imageBytes, 0, imageBytes.Length);
//物理路径
string tmpRootDir = path;
//文件路径不存在就新创建
if (!Directory.Exists(tmpRootDir))
{
Directory.CreateDirectory(tmpRootDir);
}
string imagesurl2 = tmpRootDir + imgName + "." + hz; //转换成绝对路径
// 转成图片
Image image = Image.FromStream(memoryStream);
image.Save(imagesurl2);
memoryStream.Flush();
memoryStream.Close();
memoryStream.Dispose();
return imgName + "." + hz;
}
08-19
6814
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-07
8317
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-23
210
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-03
413
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-17