我正在尝试使用.net ImageResizer将图像保存到指定的大小。我无法使用当前使用的代码将较小的图像保存到较大的尺寸。例如,我上传的图像为200x200,_thumb版本将保存为100x100,但_medium和_large版本仍为200x200。
如何将上传的图像保存到指定的较大图像?例如versions.Add(" _extraLarge"," width = 2000& height = 2000& crop = auto& format = jpg");或者版本。添加(" _XXL"," width = auto& 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;
}
}