c#,APS.NET 保存base64位格式的图片
电脑版发表于:2018/11/17 12:05
public void Upload() { //取出图片对应的base64位字符 string imgBase = Request["imgBase"]; //c#里边的base64需要把前面的申明去掉 string newbase = imgBase.Replace("data:image/jpeg;base64,", ""); base64TOImg(newbase); } /// <summary> /// 把base64转化成图片并保存 /// </summary> /// <param name="base64str"></param> private void base64TOImg(String base64str) { Byte[] streamByte = Convert.FromBase64String(base64str); System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); img.Save(Server.MapPath("~/userdata/"+Guid.NewGuid().ToString().Replace("-","")+".jpeg")); }