Hello
I wrote the function for cropping image but I believe that it is not optimal.
How can I increase the performance of my code?
Detailed task:
function should to transform existing image(cannot create a new image as the result of operation and return it) because needs to save existing profiles like as exif, iptc, etc
my idea: fill image with backgorundColor then resize it to needed size and after that combine with the clone of original image
I wrote the function for cropping image but I believe that it is not optimal.
How can I increase the performance of my code?
Detailed task:
function should to transform existing image(cannot create a new image as the result of operation and return it) because needs to save existing profiles like as exif, iptc, etc
my idea: fill image with backgorundColor then resize it to needed size and after that combine with the clone of original image
public class Cropper
{
public void Crop(MagickImage image, int x, int y, int width, int height, Color backgroundColor)
{
using (MagickImage clone = image.Clone())
{
image.FillColor = new MagickColor(backgroundColor);
image.Draw(new DrawableRectangle(0, 0, Width, Height));
image.Resize(new MagickGeometry(width, height) { IgnoreAspectRatio = true });
image.Composite(clone, new MagickGeometry(-x, -y, width, height));
}
}
}