Simple.ImageResizer
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:A simple c# image resizer with ScaleToFit and ScaleToFill using wpf libraries. Resizes to jpg, gif, png, tiff. Demosite is hosted at AppHarbor: http://imageresizer.apphb.com/
Simple C# ImageResizer library using wpf classes

Demo: [http://imageresizer.apphb.com/](http://imageresizer.apphb.com/)

Available on NuGet:
PM> Install-Package Simple.ImageResizer

Please note that this library is not related to the http://imageresizing.net/ project

Usage:
ImageResizer.ImageResizer resizer = new ImageResizer.ImageResizer(@"c:\path\to\image.jpg");

// resize to 400 px, jpg quality 90
var byteArray1 = resizer.Resize(400, ImageEncoding.Jpg90);

// resize to 400 px, height 200, ScaleToFill, png
var byteArray2 = resizer.Resize(400, 200, true, ImageEncoding.Png);

// resize to 400 px, height 200, ScaleToFit, gif
var byteArray3 = resizer.Resize(400, 200, false, ImageEncoding.Gif);

// save last resized image to file
resizer.SaveToFile(@"c:\path\to\image_resized.gif");
Or
public ActionResult Upload(HttpPostedFileBase file)
{
      var imageResizer = new ImageResizer.ImageResizer(file.InputStream.ToByteArray());
      imageResizer.Resize(800, ImageEncoding.Jpg100);
      imageResizer.SaveToFile(Path.Combine(Server.MapPath("~/upload"), file.FileName));
      return View();
}
Now also with a MvcExtensions package making it super easy to add dynamic image resizing into your asp.net mvc site. Step 1: PM> Install-Package Simple.ImageResizer.MvcExtensions Step 2: Add a ImagesController. Notice the ImageResult class which inherits FileResult and lets you add a custom width and height in the constructor. Setting both height and width to 0 will skip resizing of the image. Note: Your app will need write permission to the image folder specified as it caches resized images on disk in a subfolder.
public class ImagesController : Controller
{
        [OutputCache(VaryByParam = "*", Duration = 60 * 60 * 24 * 365)]
        public ImageResult Index(string filename, int w = 0, int h = 0)
        {
            string filepath = Path.Combine(Server.MapPath("~/images2"), filename);
            return new ImageResult(filepath, w, h);
        }
}
Step 3: Add a custom route for images allowing requests to images to be handled by our controller action.
routes.MapRoute(
        "Image", "images/{filename}",
        new { controller = "Images", action = "Index", filename = "" }
);
Step 4: Add the following to web.config in the system.webserver section to allow calls to static files to be handled by the mvc pipeline.
<modules runAllManagedModulesForAllRequests="true" />

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。