当前位置: 首页>>代码示例>>C#>>正文


C# WebImage.Save方法代码示例

本文整理汇总了C#中System.Web.Helpers.WebImage.Save方法的典型用法代码示例。如果您正苦于以下问题:C# WebImage.Save方法的具体用法?C# WebImage.Save怎么用?C# WebImage.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Helpers.WebImage的用法示例。


在下文中一共展示了WebImage.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

 public ActionResult Create([Bind(Include = "Id,Title,Slug,Body,MediaURL")] Post post, HttpPostedFileBase fileUpload)
 {
     if (ModelState.IsValid)
     {
         //Restricting the valid file formats to images only
         if (fileUpload != null && fileUpload.ContentLength > 0)
         {
             if (!fileUpload.ContentType.Contains("image"))
             {
                 return new HttpStatusCodeResult(HttpStatusCode.UnsupportedMediaType);
             }
             //var fileName = Path.GetFileName(fileUpload.FileName);
             WebImage fileName = new WebImage(fileUpload.InputStream);
             if (fileName.Width > 500)
                 fileName.Resize(500, 500);
             //fileUpload.SaveAs(Path.Combine(Server.MapPath("~/assets/img/blog/"), fileName));
             fileName.Save("~/assets/img/blog/"+fileUpload.FileName);
             post.MediaURL = "~/assets/img/blog/" + fileUpload.FileName;
         }
         var cDate = DateTimeOffset.UtcNow;
         post.CreationDate = cDate.ToLocalTime();
         db.Posts.Add(post);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(post);
 }
开发者ID:hhussain1629,项目名称:Hussain_Website,代码行数:27,代码来源:PostsController.cs

示例2: Save

        /// <summary>
        /// Saves an image to the temp directory with a given name
        /// </summary>
        /// <param name="image">Image to save</param>
        /// <param name="fileName">Name of the file to save as</param>
        /// <returns>Where the image is saved at</returns>
        public virtual string Save(WebImage image, string fileName)
        {
            var path = GetFilePath(fileName);
            image.Save(path);

            return path;
        }
开发者ID:jrolstad,项目名称:Domus,代码行数:13,代码来源:TempImageProvider.cs

示例3: Create

        public ActionResult Create(CoursePostViewModel course)
        {
            if (ModelState.IsValid)
            {
                //saving image
                var image = new WebImage(course.File.InputStream);
                var imageName = Guid.NewGuid().ToString() + "." + image.ImageFormat;
                var path = Path.Combine(Server.MapPath("~/Content/Images"), WebSecurity.CurrentUserName, "Courses");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = Path.Combine(path, imageName);
                image.Save(path);

                //saving course
                var dbCourse = ViewModelIntoEntity(course);
                dbCourse.CreatedDate = DateTime.Now;
                dbCourse.LastModifiedDate = DateTime.Now;
                dbCourse.Published = false;
                dbCourse.ImageName = imageName;
                dbCourse.ImageUrl = Path.Combine("~/Content/Images", WebSecurity.CurrentUserName, "Courses", imageName);
                db.Courses.Add(dbCourse);
                db.SaveChanges();

                return RedirectToAction("Courses", "Dashboard");
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", course.CategoryId);
            ViewBag.InstructorId = WebSecurity.CurrentUserId;
            return View(course);
        }
开发者ID:Zerek,项目名称:edurate,代码行数:32,代码来源:CourseController.cs

示例4: Save

        public ActionResult Save(string t, string l, string h, string w, string fileName)
        {
            try
            {
                // Calculate dimensions
                var top = Convert.ToInt32(t.Replace("-", "").Replace("px", ""));
                var left = Convert.ToInt32(l.Replace("-", "").Replace("px", ""));
                var height = Convert.ToInt32(h.Replace("-", "").Replace("px", ""));
                var width = Convert.ToInt32(w.Replace("-", "").Replace("px", ""));

                // Get file from temporary folder
                var fn = Path.Combine(Server.MapPath(MapTempFolder), Path.GetFileName(fileName));
                // ...get image and resize it, ...
                var img = new WebImage(fn);
                img.Resize(width, height);
                // ... crop the part the user selected, ...
                img.Crop(top, left, img.Height - top - AvatarStoredHeight, img.Width - left - AvatarStoredWidth);
                // ... delete the temporary file,...
                System.IO.File.Delete(fn);
                // ... and save the new one.
                var newFileName = Path.Combine(AvatarPath, Path.GetFileName(fn));
                var newFileLocation = HttpContext.Server.MapPath(newFileName);
                if (Directory.Exists(Path.GetDirectoryName(newFileLocation)) == false)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(newFileLocation));
                }

                img.Save(newFileLocation);
                return Json(new { success = true, avatarFileLocation = newFileName });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, errorMessage = "Unable to upload file.\nERRORINFO: " + ex.Message });
            }
        }
开发者ID:mistertommat,项目名称:AvatarUpload,代码行数:35,代码来源:AvatarController.cs

示例5: EditImage

        public ActionResult EditImage(EditorInputModel editor)
        {
            string fileName = editor.Profile.ImageUrl;
            var image = new WebImage(HttpContext.Server.MapPath("/Images/Temp/") + fileName);

            double ratio = editor.Width / 620;
            //the values to crop off.
            double top = editor.Top * ratio;
            double left = editor.Left * ratio;
            double bottom = editor.Height - editor.Bottom * ratio;
            double right = editor.Width - editor.Right * ratio;

            image.Crop((int)top, (int)left, (int)bottom, (int)right);

            //the image size I need at the end
            image.Resize(620, 280);
            image.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News"), fileName));
            System.IO.File.Delete(Path.Combine(HttpContext.Server.MapPath("/Images/Temp/"), fileName));

            var imageThumb = image;
            imageThumb.Resize(65, 50);
            imageThumb.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News/Thumb"), fileName));
            editor.Profile.ImageUrl = fileName;
            return View("Index", editor.Profile);
        }
开发者ID:NicolaNauwynck,项目名称:MVC-4-Cropper,代码行数:25,代码来源:HomeController.cs

示例6: CreateThumbnail

        public void CreateThumbnail(String filename, String directory, int width, int height, String prefix = "thumb_")
        {
            var image = new WebImage(Path.Combine(directory, filename));

            int newWidth = image.Width < image.Height ? image.Width*height/image.Height : width;
            int newHeight = image.Width < image.Height ? height : image.Height*width/image.Width;

            image.Resize(newWidth, newHeight, true).Crop(1, 1);
            image.Save(Path.Combine(directory, String.Format("{0}{1}", prefix, filename)), image.ImageFormat);
        }
开发者ID:Gromila,项目名称:JustPhotoGallery,代码行数:10,代码来源:ImageProcessing.cs

示例7: CreateThumbnail

        public static void CreateThumbnail(HttpPostedFileBase image, string folder)
        {
            var thumbnail = new WebImage(image.InputStream);
            System.Diagnostics.Debug.WriteLine(thumbnail.FileName);

            var fullPath = Path.Combine("~/" + folder + "/Thumbnails/", image.FileName);

            thumbnail.Resize(thumbWidth, thumbHeight, true);

            thumbnail.Save(fullPath, thumbnail.ImageFormat);
        }
开发者ID:krishnakant,项目名称:CampusWebstore,代码行数:11,代码来源:ImageManager.cs

示例8: UploadImage

 private ActionResult UploadImage(HttpPostedFileBase img, string sessionName)
 {
     var extension = Path.GetExtension(img.FileName);
     var tempFileName = Guid.NewGuid();
     var saveUrl = "~/ProfileImages/" + tempFileName + extension;
     var image = new WebImage(img.InputStream);
     image.Resize(150, 150);
     image.Save(saveUrl);
     Session.Add(sessionName, saveUrl);
     return Content("<img src=\"/ProfileImages/" + tempFileName + extension + "\" alt=\"\" />");
 }
开发者ID:reedcouk,项目名称:wiki-toons,代码行数:11,代码来源:FileController.cs

示例9: SaveImage

 private static void SaveImage(HttpPostedFileBase file, string filename)
 {
     WebImage img = new WebImage(file.InputStream);
     if (img.Width > Settings.Default.MaxAuthorImageWidth)
     {
         int newWidth = Settings.Default.MaxAuthorImageWidth;
         float aspectRatio = (float)img.Width / (float)img.Height;
         int newHeight = Convert.ToInt32(newWidth / aspectRatio);
         img.Resize(newWidth, newHeight).Crop(1, 1);
         img.Save(filename);
     }
 }
开发者ID:nancy-bree,项目名称:AudiofileCatalogue,代码行数:12,代码来源:FileService.cs

示例10: saveImageToServer

        public string saveImageToServer(WebImage image)
        {
            string folderPath = Server.MapPath(@"~/Images");
            if (!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);

            String newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(image.FileName);
            String fullPath = @"Images/" + newFileName;

            image.Save(@"~/" + fullPath);
            return newFileName;
        }
开发者ID:Dave1840438,项目名称:Session5-TP-MVC-Chourot,代码行数:12,代码来源:InterfaceController.cs

示例11: ResizeAndSave

        public void ResizeAndSave(Size newSize, string newPath = null)
        {
            if (string.IsNullOrEmpty(pathToFile))
                return;

            if (!File.Exists(pathToFile))
                return;

            WebImage webImage = new WebImage(pathToFile);
            webImage.Resize(newSize.Width, newSize.Height);

            webImage.Save(newPath ?? pathToFile);
        }
开发者ID:piotrcierpich,项目名称:los,代码行数:13,代码来源:ImageResizer.cs

示例12: uploadImage

 public static void uploadImage(dynamic uploadedFile,ref String guids)
 {
     var fileSavePath = "";
     BinaryReader b = new BinaryReader(uploadedFile.InputStream);
       byte[] binData = b.ReadBytes(uploadedFile.ContentLength);
       WebImage img= new WebImage(binData);
       var guid=Guid.NewGuid().ToString();
       guids = guids +""+guid+",";
       fileSavePath = System.Web.HttpContext.Current.Server.MapPath("~/images/property/" +
         guid);
       img.Resize(imageWidth,imageHeight,true);
       img.Save(fileSavePath,"jpg",true);
 }
开发者ID:kurigashvili,项目名称:realtydb,代码行数:13,代码来源:Media.cs

示例13: CropFile

        public static void CropFile(string name, string diretorio, List<ImagensLayout.Tamanho> tamanhos)
        {
            var path = MontaPath(diretorio, name);

            foreach (var item in tamanhos)
            {
                if (item.Nome == "Original")
                    continue;

                var imagem = new WebImage(path);
                var pathFotoCropada = MontaPath(diretorio, item.Altura + "x" + item.Largura + "_" + name);
                imagem.Resize(item.Largura, item.Altura);
                imagem.Save(pathFotoCropada);
            }
        }
开发者ID:JhonnyGoncalves,项目名称:Eva,代码行数:15,代码来源:ImagemHelper.cs

示例14: SaveTemporaryAvatarFileImage

        private static string SaveTemporaryAvatarFileImage(HttpPostedFileBase file, string serverPath, string fileName)
        {
            var img = new WebImage(file.InputStream);
            var ratio = img.Height / (double)img.Width;
            img.Resize(AvatarScreenWidth, (int)(AvatarScreenWidth * ratio));

            var fullFileName = Path.Combine(serverPath, fileName);
            if (System.IO.File.Exists(fullFileName))
            {
                System.IO.File.Delete(fullFileName);
            }

            img.Save(fullFileName);
            return Path.GetFileName(img.FileName);
        }
开发者ID:cuongpv88,项目名称:work,代码行数:15,代码来源:ImageUpload.cs

示例15: Crop

        public ActionResult Crop(ImageModel imageModel)
        {
            WebImage image = new WebImage(_PATH + imageModel.ImagePath);
            var height = image.Height;
            var width = image.Width;
            var top = imageModel.Top;
            var left = imageModel.Left;
            var bottom = imageModel.Bottom;
            var right = imageModel.Right;

            image.Crop(top, left, height - bottom, width - right);
            image.Resize(140, 200, false, false);
            image.Save(_PATH + imageModel.ImagePath);

            return RedirectToAction("Index");
        }
开发者ID:ramesh533,项目名称:FlickSome,代码行数:16,代码来源:MoviesController.cs


注:本文中的System.Web.Helpers.WebImage.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。