If I run a Composite with CopyAlpha across an image and a black/white mask, I can correctly show the image in a picture box in a dummy Winform app, but can't seem to save the changes. On save or output to stream etc. I just get back the original image. Maybe I need to flatten or something but I can't figure it out.
Consider the following sample winform with a picturebox control and a button:
Code: Select all
private void button1_Click(object sender, EventArgs e)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
MagickImage image = new MagickImage(path + @"\testimage.jpg");
MagickImage mask = new MagickImage(path + @"\testimage_mask.jpg");
//Remove everything that isn't the mask
image.Composite(mask, ImageMagick.CompositeOperator.CopyAlpha);
//Perfect! picture box shows correctly croppedimage.
pictureBox1.Image = image.ToBitmap();
//However, when I output Write to file, or even to bitmap and then save afterward, the _original_ file unmodified by the Composite is saved.
image.Write(path + @"\output.jpg");
image.ToBitmap().Save(path + @"\output_2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
Thanks a bunch!