我一直在尋找真棒imageresizing.net工具,併成功地在我的網站上使用URL API。WebMatrix - 使用ImageResizer與圖像上傳
但是,我很想看看託管API,並調整照片上傳的大小。我已經通過構建一個使用WebImage助手一個非常基本的上傳頁面開始了:
@using ImageResizer;
@{
WebImage photo = null;
var newFileName = "";
var imagePath = "";
if(IsPost){
photo = WebImage.GetImageFromRequest();
if(photo != null){
newFileName = Guid.NewGuid().ToString() + "_" +
Path.GetFileName(photo.FileName);
imagePath = @"images\" + newFileName;
photo.Save(@"~\" + imagePath);
}
}
}
我想在此上傳使用ImageResizing工具,調整大小/作物爲特定的大小。
下面是我需要插入的代碼(我有一個現有的圖像上運行進行了測試,它工作正常):
ImageResizer.ImageBuilder.Current.Build(imagePath,imagePath,
new ResizeSettings("width=620&height=405&mode=crop"));
任何想法的房子,我可以合併兩個,而之前調整我救人?
我還抄在這裏找到的建議http://stackoverflow.com/questions/14064563/mvc3-imageresizer但是當我運行頁面,我得到一個錯誤說「源可能只是字符串的一個實例,VirtualFile,IVirtualBitmapFile,HttpPostedFile,HttpPostedFileBase,Bitmap,Image或Stream。 參數名稱:source「 – Gavin5511
你給它一個WebImage實例嗎?不要使用WebImage,[WebImage是邪惡的](http://stackoverflow.com/questions/9710448/asp-net-web-pages-using-webimage-to-resize-and-save-a-photo)。這裏也沒用/毫無意義。直接給ImageResizer上傳。 –