NOTE / WebImage

使用WebImage 調整圖像大小像速比

private static void CropImage (HttpPostedFileBase sourceImage) {
  var newImage = new WebImage(sourceImage.InputStream);
  var width = newImage.Width;
  var height = newImage.Height;
  if (width > height) {
    var leftRightCrop = (width - height) / 2;
    newImage.Crop(0, leftRightCrop, 0, leftRightCrop);
  }
  else if (height > width) {
    var topBottomCrop = (height - width) / 2;
    newImage.Crop(topBottomCrop, 0, topBottomCrop, 0);
  }
//do something with cropped image...
newImage.GetBytes();
}
HttpPostedFileBase myFile = Request.Files[0];
WebImage img = new WebImage(myFile.InputStream);
int width = img.Width;
int height = img.Height;
if (width > height)
{
  int leftRightCrop = (width - height) / 2;
  img.Crop(0, leftRightCrop, 0, leftRightCrop);
}
else if (height > width)
{
  int topBottomCrop = (height - width) / 2;
  img.Crop(topBottomCrop, 0, topBottomCrop, 0);
}
下面這段式調整好的大小比因為寬高有固定所以直接設等比
WebImage img_cropped = img.Resize(226, 280, true, true);

REFERENCE / 1

Loading