diff --git a/DBControllers/ImageController.cs b/DBControllers/ImageController.cs index 4209072..130c47c 100644 --- a/DBControllers/ImageController.cs +++ b/DBControllers/ImageController.cs @@ -17,9 +17,16 @@ namespace NeDvachAPI.DBControllers public static bool ResizeImage(string picPath, string smallPath, int width, int height) { - var dstInfo = new SKImageInfo(height, width); + var bitmap = SKBitmap.Decode(picPath); + double ratio = Math.Max((double)bitmap.Width / (double)width , (double)bitmap.Height / (double)height); + int targetWidth = (int)(bitmap.Width/ ratio); + int targetHeight = (int)(bitmap.Height / ratio); + + Console.WriteLine($"Ресайзим картинку до {targetWidth} ширины и {targetHeight} высоты."); + + var dstInfo = new SKImageInfo(targetWidth , targetHeight); var image = SKImage.FromBitmap(bitmap.Resize(dstInfo, SKFilterQuality.Medium)); var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);