Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Cropping image

$
0
0
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
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));
        }
    }
}

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>