Resize now keeps aspect ratio.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
35139d66a2
commit
2d853eaa02
@ -17,9 +17,16 @@ namespace NeDvachAPI.DBControllers
|
|||||||
|
|
||||||
public static bool ResizeImage(string picPath, string smallPath, int width, int height)
|
public static bool ResizeImage(string picPath, string smallPath, int width, int height)
|
||||||
{
|
{
|
||||||
var dstInfo = new SKImageInfo(height, width);
|
|
||||||
var bitmap = SKBitmap.Decode(picPath);
|
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 image = SKImage.FromBitmap(bitmap.Resize(dstInfo, SKFilterQuality.Medium));
|
||||||
var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);
|
var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user