ImageResizer - 将图像保存为更大尺寸
Posted
技术标签:
【中文标题】ImageResizer - 将图像保存为更大尺寸【英文标题】:ImageResizer - Save Image as a Larger Size 【发布时间】:2014-11-03 18:53:22 【问题描述】:我正在尝试使用 .net ImageResizer 将图像保存为指定大小。我无法使用我正在使用的当前代码将较小的图像保存到较大的尺寸。例如,我上传的图片是 200x200,_thumb 版本会保存为 100x100,但 _medium 和 _large 版本仍然是 200x200。
如何将上传的图片保存为指定的大图?如versions.Add("_extraLarge", "width=2000&height=2000&crop=auto&format=jpg");或versions.Add("_XXL", "&height=3000&crop=auto&format=jpg");
//GenerateVersions(FileUpload1.PostedFile.FileName);
Dictionary<string, string> versions = new Dictionary<string, string>();
//Define the versions to generate
versions.Add("_thumb", "width=100&height=100&crop=auto&format=jpg"); //Crop to square thumbnail
versions.Add("_medium", "maxwidth=400&maxheight=400&format=jpg"); //Fit inside 400x400 area, jpeg
versions.Add("_large", "maxwidth=1900&maxheight=1900&format=jpg"); //Fit inside 1900x1200 area
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
//Get the physical path for the uploads folder and make sure it exists
string uploadFolder = MapPath("~/uploadsAIM");
if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder);
//Generate each version
foreach (string suffix in versions.Keys)
////Generate a filename (GUIDs are best).
//string fileName = Path.Combine(uploadFolder, System.Guid.NewGuid().ToString() + suffix);
string fileName = Path.Combine(uploadFolder, file.FileName + suffix);
//Let the image builder add the correct extension based on the output file type
//fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); //deprecated fileName
fileName = ImageBuilder.Current.Build(new ImageJob(file, fileName, new Instructions(versions[suffix]), false, true)).FinalPath;
【问题讨论】:
将低分辨率图像调整为更高分辨率并不能使其成为高质量。相反,它会模糊图像。 是的。我可以使用什么来进行分形插值或其他东西来调整放大的图像? 【参考方案1】:默认情况下,缩放模式设置为DownscaleOnly
。根据您的需要,将说明中的Scale
设置为up
or both
。
请注意,放大图像会产生模糊的图像。
【讨论】:
以上是关于ImageResizer - 将图像保存为更大尺寸的主要内容,如果未能解决你的问题,请参考以下文章