Base64StringToImage

protected string Base64StringToImage(string strbase64)
{
string gid = Guid.NewGuid().ToString();

string imagepath = HttpRuntime.AppDomainAppPath.ToString() + "tempImage";
if (!Directory.Exists(imagepath))
{
Directory.CreateDirectory(imagepath);
}
string path = imagepath + "/" + gid + ".jpg";

try
{
byte[] arr = Convert.FromBase64String(strbase64);
MemoryStream ms = new MemoryStream(arr);
Bitmap bmp = new Bitmap(ms);
bmp.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Close();
path = "https://wxapp.lqfast.com/tempImage" + "/" + gid + ".jpg";
return path;
}
catch (Exception ex)
{
return "";
}
}

posted on 2018-09-12 09:51  高达  阅读(536)  评论(0)    收藏  举报

导航