js
var url = canvas.toDataURL();//把canvas中的图片变成data:image
C#
string filepath = "";
string imgData = Request["url"].ToString();
var date = DateTime.Now.ToString("yyyyMMddmsms");
if (imgData.StartsWith("data:image/png;base64") == true)
{
var base64 = imgData.Substring(22);
byte[] bytes = Convert.FromBase64String(base64);
MemoryStream memStream = new MemoryStream(bytes);
BinaryFormatter binFormatter = new BinaryFormatter();
var img = System.Drawing.Image.FromStream(memStream);
filepath = "~/images/output/" + date + ".png";
if (!Directory.Exists(Server.MapPath("~/images/output")))
{
Directory.CreateDirectory(Server.MapPath("~/images/output"));
}
img.Save(Server.MapPath(filepath));
}