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

New Post: Cropping

$
0
0
I actually got around it using the MagickImage crop and some cloning. :)
var data = imageData[i];
var files = Directory.GetFiles(imageOutputDirectory + "\\", data.filename.Substring(0, data.filename.IndexOf(".")) + " *.png");
foreach (var file in files)
{
    File.Delete(file);
}

var img = new MagickImage(data.path);
var horizontalChunks = img.Width/data.chunkSize.X;
var verticalChunks = img.Height/data.chunkSize.Y;
var transparent = new MagickImage(new MagickColor(Color.Transparent), data.chunkSize.X, data.chunkSize.Y);

for (int x = -data.positionalOffset.X; x < horizontalChunks - data.positionalOffset.X; x++)
{
    for (int y = -data.positionalOffset.Y; y < verticalChunks - data.positionalOffset.Y; y++)
    {
        var clone = img.Clone();
        clone.Crop(new MagickGeometry((x + data.positionalOffset.X) * data.chunkSize.X, (y + data.positionalOffset.Y) * data.chunkSize.Y, data.chunkSize.X, data.chunkSize.Y));
        if(!clone.Equals(transparent))
            clone.Write(imageOutputDirectory + "\\" + data.filename.Substring(0, data.filename.IndexOf(".")) + " " + x + "_" + y + ".png");
        }
}

Viewing all articles
Browse latest Browse all 3693

Trending Articles