我使用 WebImage 来调整图像大小:
[ImageOutputCache(Duration = 3000, Location = System.Web.UI.OutputCacheLocation.Client)]
public void GetPic(string fn, int? w, int? h)
{
try
{
if (w > 1920) { w = 1920; }
if (h > 1080) { h = 1080; }
WebImage wi = new WebImage(@"~/img/" + fn);
if (!h.HasValue)
{
Single ratio = (Single)wi.Width / (Single)wi.Height;
h = (int)Math.Ceiling(wi.Width / ratio);
}
wi
.Resize(w.Value + 1, h.Value + 1, true, true) // Resizing the image to 100x100 px on the fly...
.Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage)
.Write();
}
catch
{
//new WebImage(@"~/img/default.jpg").Write();
//Redirect(@"~/img/default.jpg");
}
}
我想使用重定向到默认图像而不是 webimage.write (请参阅捕获部分)。我怎么能做到。