public ActionResult uploadify() { string type = WebRequest.GetString("type", true); string code = WebRequest.GetString("code", true); string uploadsFolder = ""; #region 图片存储路径 if (type == "operationlog") { uploadsFolder = HttpContext.Server.MapPath("~/Content/operationlog/" + code); } #endregion //string uploadsFolder = HttpContext.Server.MapPath("~/Content/uploadfile"); Guid identifier = Guid.NewGuid(); var uploadsPath = Path.Combine(uploadsFolder, identifier.ToString()); var httpfile = Request.Files["Filedata"]; var fn = httpfile.FileName; var exn = fn.Substring(fn.LastIndexOf(".")); if (httpfile != null) { if (!Directory.Exists(uploadsFolder)) { Directory.CreateDirectory(uploadsFolder); } httpfile.SaveAs(uploadsPath + exn); #region 图片自动裁剪 if (exn.ToLower().Contains("jpg")) { string sourceFile = uploadsPath + exn; // Server.MapPath("~/Content/images/" + name);//源图存放目录 string newFile = string.Empty; //新图路径 string newNewDir = Server.MapPath("~/Content/pressimg/"); //新图存放目录 newFile = Path.Combine(newNewDir, "正方形裁剪.jpg"); ImageCutZoom.CutForSquare(sourceFile, newFile, 200, 90); newFile = Path.Combine(newNewDir, "180_240.jpg"); ImageCutZoom.CutForCustom(sourceFile, newFile, 240, 180, 100); newFile = Path.Combine(newNewDir, "等比180_240.jpg"); ImageCutZoom.ZoomAuto(sourceFile, newFile, 240, 180, "", ""); } #endregion //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失 return(Content("1")); } else { return(Content("0")); } }
public ContentResult imgpress(string name, int height, int width, int per) { string sourceFile = Server.MapPath("~/Content/images/" + name); //源图存放目录 string newNewDir = Server.MapPath("~/Content/pressimg/"); //新图存放目录 string newFile = string.Empty; //新图路径 string result = ""; string n = name.Substring(0, name.Length - 4); newFile = Path.Combine(newNewDir, n + "w_定高按宽度缩放.jpg"); bool r = ImageCompress.Thumbnail(sourceFile, newFile, height, width, 80, ImageCompress.ZoomType.H); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "w_定宽按高度缩放.jpg"); r = ImageCompress.Thumbnail(sourceFile, newFile, height, width, 80, ImageCompress.ZoomType.W); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "wh_指定高宽缩放.jpg"); r = ImageCompress.Thumbnail(sourceFile, newFile, height, width, 80, ImageCompress.ZoomType.WH); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "wh_指定高宽裁剪.jpg"); r = ImageCompress.Thumbnail(sourceFile, newFile, height, width, 80, ImageCompress.ZoomType.Cut); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "原图%" + per + ".jpg"); r = ImageCompress.Cut(sourceFile, newFile, height, width, per, true); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "h_w指定高宽缩放.jpg"); r = ImageCompress.Cut(sourceFile, newFile, height, width, 30, false); result += r.ToString(); newFile = Path.Combine(newNewDir, n + "正方形裁剪.jpg"); ImageCutZoom.CutForSquare(sourceFile, newFile, 200, 90); newFile = Path.Combine(newNewDir, n + "180_240.jpg"); ImageCutZoom.CutForCustom(sourceFile, newFile, 240, 180, 100); newFile = Path.Combine(newNewDir, n + "等比180_240.jpg"); ImageCutZoom.ZoomAuto(sourceFile, newFile, 240, 180, "", ""); return(Content(result)); }