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


C# WebImage.Resize方法代码示例

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


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

示例1: FileUpload

        public ActionResult FileUpload(HttpPostedFileBase file)
        {
            if (file != null && file.ContentType.StartsWith("image/"))
            {
                WebImage img = new WebImage(file.InputStream);
                if (img.Width > 178)
                {
                    img.Resize(178, img.Height);
                }

                if (img.Height > 178)
                {
                    img.Resize(img.Width, 178);
                }

                //string path = "C:\\Users\\dzlatkova\\Desktop\\Images";

                //if (!Directory.Exists(path))
                //{
                //    DirectoryInfo di = Directory.CreateDirectory(path);
                //    di.Attributes &= ~FileAttributes.ReadOnly;
                //}

                //string filePath = Path.Combine(path, Path.GetFileName(file.FileName));

                //file.SaveAs(path);

                db.Employers.FirstOrDefault(x => x.UserId == WebSecurity.CurrentUserId).Picture = img.GetBytes();
                db.SaveChanges();
            }
            return RedirectToAction("Profile");
        }
开发者ID:nikup,项目名称:occupie,代码行数:32,代码来源:EmployerController.cs

示例2: CreateImage

        public ActionResult CreateImage(string format, string id)
        {
            var relName = $"~/App_Data/covers/{id}.jpg";
            var absName = Server.MapPath(relName);

            if (!System.IO.File.Exists(absName))
            {
                return HttpNotFound();
            }

            var img = new WebImage(absName);

            switch (format.ToLower())
            {
                case "thumb":
                    img.Resize(100, 1000).Write();
                    break;

                case "medium":
                    img.Resize(300, 3000)
                        .AddTextWatermark("Ingars Movie Database")
                        .AddTextWatermark("Ingars Movie Database", "White", padding: 7)
                        .Write();
                    break;

                default:
                    return HttpNotFound();
            }

            return new EmptyResult();
        }
开发者ID:ProgramUtvikling,项目名称:mvckurs-sept-2015,代码行数:31,代码来源:ImageController.cs

示例3: 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

示例4: Download

        public ActionResult Download(int id, bool? thumb)
        {
            var context = HttpContext;
            var mediaItem = Database.MediaItems.SingleOrDefault(m => m.Id == id);
            if (mediaItem == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }
            var filePath = Path.Combine(StorageRoot(mediaItem.MediaType), mediaItem.FileName);
            if (!System.IO.File.Exists(filePath))
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);

            const string contentType = "application/octet-stream";

            if (thumb.HasValue && thumb == true)
            {
                var img = new WebImage(filePath);
                if (img.Width > 120)
                    img.Resize(120, 110).Crop(1, 1);
                return new FileContentResult(img.GetBytes(), contentType)
                    {
                        FileDownloadName = mediaItem.FileName
                    };
            }
            else
            {
                return new FilePathResult(filePath, contentType)
                    {
                        FileDownloadName = mediaItem.FileName
                    };
            }
        }
开发者ID:kasparo,项目名称:ZaDvermiWeb,代码行数:32,代码来源:FileController.cs

示例5: 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

示例6: 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

示例7: Edit

        public ActionResult Edit(long id, HttpPostedFileBase boxFile, 
            HttpPostedFileBase bdate,
            HttpPostedFileBase box1, 
            HttpPostedFileBase box2, 
            HttpPostedFileBase box3,
            HttpPostedFileBase box4)
        {
			
            var item = GetSession.Get<Setting>(id);
            var homePath = Server.MapPath("~/public/userfiles/home/boximage.jpg");

            if (boxFile != null)
            {
                boxFile.SaveAs(string.Format(homePath));
            }

            homePath = Server.MapPath("~/public/userfiles/home/bdate.jpg");
            if (bdate != null)
            {
                bdate.SaveAs(string.Format(homePath));
            }

            homePath = Server.MapPath("~/public/userfiles/home/box1.jpg");
            if (box1 != null)
            {
                var image = new WebImage(box1.InputStream);
                image.Resize(500,212).Crop(1, 1).Save(string.Format(homePath));
            }

            homePath = Server.MapPath("~/public/userfiles/home/box2.jpg");
            if (box2 != null)
            {

                var image = new WebImage(box2.InputStream);
                image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
               
            }

            homePath = Server.MapPath("~/public/userfiles/home/box3.jpg");
            if (box3 != null)
            {
                var image = new WebImage(box3.InputStream);
                image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
            }

            homePath = Server.MapPath("~/public/userfiles/home/box4.jpg");
            if (box4 != null)
            {
                var image = new WebImage(box4.InputStream);
                image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
            }



			UpdateModel(item);

			GetSession.Update(item);

			return RedirectToAction("Edit");
		}
开发者ID:Avimunk,项目名称:soglowek.tmgroup,代码行数:60,代码来源:SettingsController.cs

示例8: Edit

        public async Task<ActionResult> Edit(ProfileViewModel model, HttpPostedFileBase upload)
        {
            var user = _userManager.FindById(User.Identity.GetUserId());
            if (user == null)
            {
                return RedirectToAction("Start", "Main");
            }

            if (upload != null && upload.ContentLength > 0)
            {
                WebImage img = new WebImage(upload.InputStream);
                if (img.Width > 32)
                    img.Resize(32, 32);
                user.Avatar = img.GetBytes();
            }

            user.FirstName = model.FirstName;
            user.LastName = model.LastName;
            user.UserName = model.Username;
            user.Email = model.Email;

            await _userManager.UpdateAsync(user);

            return RedirectToAction("Details", "Profile");
        }
开发者ID:squla,项目名称:projekt-zespolowy,代码行数:25,代码来源:ProfileController.cs

示例9: CreateImage

		public async Task<ActionResult> CreateImage(string format, string id)
		{
			// koble til en storage-account
			var connectionString = CloudConfigurationManager.GetSetting("msu2015_AzureStorageConnectionString");
			var acct = CloudStorageAccount.Parse(connectionString);

			// åpne en konteiner
			var client = acct.CreateCloudBlobClient();

			var container = client.GetContainerReference("covers");
			
			// hente en fil
			var blob = container.GetBlockBlobReference($"{id}.jpg");

			if (!await blob.ExistsAsync()) return HttpNotFound();

			using (var ms = new MemoryStream())
			{
				// laste ned som stream
				await blob.DownloadToStreamAsync(ms);


				var img = new WebImage(ms);

				switch (format.ToLower())
				{
					case "thumb":
						img.Resize(100, 1000)
							.Write();
						return new EmptyResult();

					case "medium":
						img.Resize(300, 3000)
							.AddTextWatermark("Ingars Movie Database")
							.AddTextWatermark("Ingars Movie Database", "White", padding: 7)
							.Write();
						return new EmptyResult();

					default:
						return HttpNotFound();
				}
			}
		}
开发者ID:ProgramUtvikling,项目名称:MSU2015,代码行数:43,代码来源:ImageController.cs

示例10: SubirImagen

        private string SubirImagen(WebImage imagen, int dimensionMaxima, string rutaDirectorio)
        {
            var isWide = imagen.Width > imagen.Height;
            var bigestDimension = isWide ? imagen.Width : imagen.Height;

            if (bigestDimension > dimensionMaxima)
            {
                if (isWide)
                    imagen.Resize(dimensionMaxima, ((dimensionMaxima * imagen.Height) / imagen.Width));
                else
                    imagen.Resize(((dimensionMaxima * imagen.Width) / imagen.Height), dimensionMaxima);
            }
            string nombreArchivo = GenerarUnNombreUnico(Path.GetFileName(imagen.FileName));

            GuardarImagen(imagen, rutaDirectorio, nombreArchivo);
            // GuardarImagenEnServidor();

            return nombreArchivo;
        }
开发者ID:acapdevila,项目名称:Blog-MVC5,代码行数:19,代码来源:SubirArchivoImagenServicio.cs

示例11: 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

示例12: ResizePhoto

        private static WebImage ResizePhoto(PhotoSize photoSize, byte[] blobBytes)
        {
            var webImage = new WebImage(blobBytes);
            switch (photoSize)
            {
                case PhotoSize.Small:
                    webImage = webImage.Resize(64, 64, true, true);
                    break;

                case PhotoSize.Medium:
                    webImage = webImage.Resize(128, 128, true, true);
                    break;

                case PhotoSize.Large:
                    webImage = webImage.Resize(256, 256, true, true);
                    break;
            }

            return webImage;
        }
开发者ID:Bowman74,项目名称:Badge-Application,代码行数:20,代码来源:ImageController.cs

示例13: 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

示例14: 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

示例15: 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


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