//Save as Image file function ShanuSaveImage() { var m = confirm("Are you sure to Save "); if (m) { // generate the image data var image_NEW = document.getElementById("canvas").toDataURL("image/png"); image_NEW = image_NEW.replace(´data:image/png;base64,´, ´´); $.ajax({ type: ´POST´, url: ´Default.aspx/SaveImage´, data: ´{ "imageData" : "´ + image_NEW + ´" }´, contentType: ´application/json; charset=utf-8´, dataType: ´json´, success: function (msg) { alert(´Image saved to your root Folder !´); } }); } } 这是Web方法在画布上的图像存储到根文件夹。
[WebMethod()] public static void SaveImage(string imageData) { Random rnd = new Random(); String Filename = HttpContext.Current.Server.MapPath("Shanuimg" + rnd.Next(12, 2000).ToString() + ".png"); string Pic_Path = Filename;//HttpContext.Current.Server.MapPath("ShanuHTML5DRAWimg.png"); using (FileStream fs = new FileStream(Pic_Path, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData); bw.Write(data); bw.Close(); } } } 与HTML5工作是很有趣。我希望你喜欢读我的文章。我会很高兴。
源码下载链接: ?bdkey=s/1hqDY0Pe 密码: fgwa