Issue saving - Composite changes not persisted.
Posted: 2017-07-26T06:33:24-07:00
Hello, Please forgive me if I'm missing something obvious but I've been banging my head against a problem in Magick.net.
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:
Incidentally, the same thing happens if I write to stream, or open the ToBitmap() output with other image type constructors etc.
Thanks a bunch!
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!