HTML5图片canvas等比例缩放后上传

2019-04-15 17:55发布

图片等比例缩放后上传

上传图片

选择文件

结果

    public ActionResult SavePictureByBase64() { String fileExt = ".jpg"; try { String filename = MSCL.Until.GetGuid() + fileExt; String filepath = Server.MapPath(UploadFolder); String photoFullName = Path.Combine(filepath, filename); //创建写入文件 FileStream fs1 = new FileStream(photoFullName, FileMode.Create, FileAccess.Write); fs1.Close(); byte[] arr = Convert.FromBase64String(Request["sendData"]); MemoryStream ms = new MemoryStream(arr); Bitmap bmp = new Bitmap(ms); bmp.Save(photoFullName, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Close(); fs1.Close(); return Json(new { status = true, msg = string.Format("{0}/{1}/{2}", Url, UploadFolderName, filename) }); } catch (Exception ex) { return Json(new { status = false, msg = "上传失败" }); } } #endregion