Вот мой код:
Код: Выделить всё
public void ResizeCropAndSaveImage(IFormFile file, int cropWidth, int cropHeight, string filePath, string fileName)
{
using (Image image = Image.Load(file.OpenReadStream()))
{
// get the shorter side & scale percentages
var ratio = Math.Min((float)image.Width / cropWidth, (float)image.Height / cropHeight);
var scaleH = Convert.ToInt32(cropHeight * ratio);
var scaleW = Convert.ToInt32(cropWidth * ratio);
// set crop from center coordinates
var posX = (image.Width - scaleW) / 2;
var posY = (image.Height - scaleH) / 2;
var resizedImage = image.Clone(i => i.Resize(cropWidth, cropHeight).Crop(new Rectangle(posX, posY, scaleW, scaleH)));
Directory.CreateDirectory(filePath);
resizedImage.Save(Path.Combine(filePath, fileName), new JpegEncoder());
}
}
System.ArgumentException: прямоугольник обрезки должен быть меньше границ источника. (Параметр «cropRectangle»)
Ошибка кажется понятной, но новый Rectangle() меньше исходных изображений, поэтому я я не понимаю, что происходит?
Подробнее здесь: https://stackoverflow.com/questions/786 ... rows-error
Мобильная версия