Issue saving - Composite changes not persisted.

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
heh3d
Posts: 1
Joined: 2017-07-25T15:22:27-07:00
Authentication code: 1151

Issue saving - Composite changes not persisted.

Post 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!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Issue saving - Composite changes not persisted.

Post by dlemstra »

You are saving the image as a JPG. This format has no transparency.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Issue saving - Composite changes not persisted.

Post 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).
snibgo's IM pages: im.snibgo.com
Post Reply