public ActionResult Create(GalleryCreateViewModel galleryCreate) { var image = galleryCreate.Image; var imageSave = WorkImage.CreateImage(galleryCreate.Image, 800, 600); if(imageSave!=null) { string path = Server.MapPath("~/Upload/ImageGallery/"); string fileName = Guid.NewGuid().ToString() + ".jpg"; imageSave.Save(path + fileName, ImageFormat.Jpeg); } return View(); }
public ActionResult Create(HttpPostedFileBase image) { Bitmap imageSave = WorkImage.CreateImage(image, 800, 600); if (imageSave != null) { string path = Server.MapPath(ConfigurationManager.AppSettings["ImagePathGallery"]); string fileName = Guid.NewGuid().ToString() + ".jpg"; imageSave.Save(path + fileName, ImageFormat.Jpeg); } return(View()); }
private void SaveImages(HttpPostedFileBase[] Images, int postId, string path, int height, int width, string miniPath, int miniHeight, int miniWidth) { foreach (var img in Images) { string name = Path.GetFileName(img.FileName); string miniName = Path.GetFileName(img.FileName); Bitmap imgs = WorkImage.CreateImage(img, width, height); Bitmap miniImg = WorkImage.CreateImage(img, miniHeight, miniWidth); int i = 1; if (imgs != null) { string[] dirs = Directory.GetFiles(path, name); while (dirs.Length != 0) { name = "copy-" + i + "-" + Path.GetFileName(img.FileName); i++; dirs = Directory.GetFiles(path, name); } string filename = path + name; imgs.Save(filename, ImageFormat.Jpeg); } int h = 1; if (miniImg != null) { string[] miniDirs = Directory.GetFiles(miniPath, miniName); while (miniDirs.Length != 0) { miniName = "copy-" + h + "-" + Path.GetFileName(img.FileName); h++; miniDirs = Directory.GetFiles(miniPath, miniName); } string filename = miniPath + miniName; miniImg.Save(filename, ImageFormat.Jpeg); } SaveImage(name, miniName, postId); } }