public async Task <IActionResult> ReSize([FromQuery] ImageResizeInputModel imageResizeInputModel) { if (ModelState.IsValid) { return(BadRequest(ModelState)); } var modifiedImage = await _imageProcessor.ReSizeImage(imageResizeInputModel); return(File(modifiedImage.ImageAsBytes, modifiedImage.ImageFormat)); }
public async Task <ModifiedImage> ReSizeImage(ImageResizeInputModel imageResizeInputModel) { var image = await _imageService.GetImageAsSkBitmap(imageResizeInputModel.Url); var info = GetImageInfo(imageResizeInputModel); var encoding = imageResizeInputModel.GetEncoding(); using (var surface = SKSurface.Create(info)) { var sourceRect = new SKRect(0, 0, image.Width, image.Height); var destRect = GetDestinationRectangle(imageResizeInputModel); surface.Canvas.DrawBitmap(image, sourceRect, destRect); return(await _imageService.SaveImage(surface, encoding, imageResizeInputModel.JpegQuality)); } }