Base64编码转换为图片
/// <summary> /// 图片上传 Base64解码 /// </summary> /// <param name="dataURL">Base64数据</param> /// <param name="path">保存路径</param> /// <param name="imgName">图片名字</param> /// <param name="imgSuffix">后缀名</param> /// <returns>返回一个相对路径</returns> public static string DecodeBase64ToImage(string dataBase64, string path, string imgName,string imgSuffix) { string filename = "";//声明一个string类型的相对路径 String base64 = dataBase64.Substring(dataBase64.IndexOf(",") + 1); filename = path + "/" + imgName + imgSuffix;//所要保存的相对路径及名字 try { String inputStr = base64; byte[] arr = Convert.FromBase64String(inputStr); using (MemoryStream ms2 = new MemoryStream(arr)) { System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2); bmp2.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg); bmp2.Dispose(); } } catch (Exception ex) { string msg = ex.Message; } return filename;//返回相对路径 }