public void ScaleImage(string destination, string fileName, Quadrilateral quadrilateral, ImageFormat imageFormatOverride = null, CroppedDetails croppedDetails = null) { var newQuadrilateral = quadrilateral.Scale(this.Image.Width, this.Image.Height); this.ResizeImage(destination, fileName, newQuadrilateral, imageFormatOverride, croppedDetails); }
public void ResizeImage(string destination, string fileName, Quadrilateral quadrilateral, ImageFormat imageFormatOverride = null, CroppedDetails croppedDetails = null) { var imageFromFile = this.Image; if (croppedDetails != null) { var croppedTile = new Bitmap(croppedDetails.Width, croppedDetails.Height); croppedTile.SetResolution(this.Image.HorizontalResolution, this.Image.VerticalResolution); var croppedGraphic = Graphics.FromImage(croppedTile); var croppedArea = new Rectangle(croppedDetails.X1, croppedDetails.Y1, croppedDetails.Width, croppedDetails.Height); croppedGraphic.DrawImage(this.Image, 0, 0, croppedArea, GraphicsUnit.Pixel); imageFromFile = croppedTile; } var newImage = new Bitmap(quadrilateral.Width, quadrilateral.Height); newImage.SetResolution(imageFromFile.HorizontalResolution, imageFromFile.VerticalResolution); Graphics.FromImage(newImage) .DrawImage(imageFromFile, 0, 0, quadrilateral.Width, quadrilateral.Height); if (imageFormatOverride == null) { var fileNameNew = string.Concat(destination, "//", fileName, this.Extension); newImage.Save(fileNameNew, this.ImageFormat); } else { var extension = this.ToExension(imageFormatOverride); var fileNameNew = string.Concat(destination, "//", fileName, extension); newImage.Save(fileNameNew, imageFormatOverride); } }