Код: Выделить всё
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: Crop rectangle should be smaller than the source bounds. (Parameter 'cropRectangle')Подробнее здесь: https://stackoverflow.com/questions/786 ... rows-error
Мобильная версия