I’ve been working on a pet project of mine Site Travelers, and I needed a easy way to crop images that were uploaded to the server (ASP.NET). Obviously I knew how to do this the manual way, but this is one of those all too common cases of functionality that many people require. So, using my trusty search engine, I went shopping. There are quite a few good examples out there on how to do it, including writing helper functions, but I wanted something already packaged. I hit the jackpot when I came across a library from Code Carvings. They have a really slick image manipulation library called piczard. Their documentation is fantastic and easy to read with plenty of examples to get you down the road. Using this library reduced everything I needed to do, crop and get bytes of data, down to the following 2 lines!
FixedResizeConstraint constraint = new FixedResizeConstraint(180, 120);
byte[] bytes = constraint.SaveProcessedImageToByteArray(
file.InputStream,
new JpegFormatEncoderParams(60));
No comments:
Post a Comment