Page 1 of 1

Issue saving - Composite changes not persisted.

Posted: 2017-07-26T06:33:24-07:00
by heh3d
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:

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);
        }
Incidentally, the same thing happens if I write to stream, or open the ToBitmap() output with other image type constructors etc.

Thanks a bunch!

Re: Issue saving - Composite changes not persisted.

Posted: 2017-07-27T09:06:13-07:00
by dlemstra
You are saving the image as a JPG. This format has no transparency.

Re: Issue saving - Composite changes not persisted.

Posted: 2017-12-05T06:03:55-07:00
by snibgo
PNG, like most formats, has transparency. JPEG, and TIFF with JPEG compression, has none. GIF has only binary transparency (each pixel is either fully opaque or fully transparent).