2014-11-03 48 views
0

我試圖使用.net ImageResizer將圖像保存爲指定的尺寸。我無法使用當前正在使用的代碼將較小的圖像保存到較大的尺寸。例如,我上傳的圖片爲200x200,_thumb版本將保存爲100x100,但_medium和_large版本仍將爲200x200。ImageResizer - 將圖像保存爲較大的尺寸

如何將上傳的圖像保存到指定的較大圖像?如versions.Add(「_ extraLarge」,「width = 2000 & height = 2000 & crop = auto & format = jpg」);或版本.Add(「_ 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; 
    } 
} 
+0

將低分辨率圖像調整爲更高的分辨率不會使其質量更高。相反,它會模糊圖像。 – 2014-11-03 19:26:53

+0

是的。我可以使用哪些分形插值或調整放大圖像? – BrettKB 2014-11-03 21:27:30

回答

2

默認情況下,縮放模式設置爲DownscaleOnly。根據您的需要,將指示上的Scale設置爲up or both

請注意,放大圖像往往會產生模糊的圖像。