base64位代码转图片文件并保存到文件夹的解决方案

#region Base64 转图片方法
protected string Base64StringToImage(string strbase64)
{
try
{
string imgurl = Server.MapPath("~/Img");
byte[] arr = Convert.FromBase64String(strbase64);
MemoryStream ms = new MemoryStream(arr);
Bitmap bmp = new Bitmap(ms);
var uuid = Guid.NewGuid().ToString();
bmp.Save(@"" + imgurl + "/" + uuid + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Close();
string url = Request.Url.ToString();
url = (url.Split('/')[0] + "//" + url.Split('/')[1] + url.Split('/')[2]).ToString();
return "" + url + "/Img/" + uuid + ".jpg";
}
catch (Exception ex)
{
return null;
}
}
#endregion

上一篇:C# ASP.NET Webservice调用外部exe无效的解决方法


下一篇:浅谈 OpenGL 中相关阻塞问题