gpt4 book ai didi

c# - WebImage 裁剪成正方形

转载 作者:太空狗 更新时间:2023-10-29 20:50:50 24 4
gpt4 key购买 nike

有谁知道如何使用新的 ASP.Net MVC 3 Html Helper 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();
}

关于c# - WebImage 裁剪成正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4535193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com