Update PixelCollection

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
Posts: 51
Joined: 2016-05-07T06:47:14-07:00
Authentication code: 1151

Update PixelCollection

Post by pablobhz » 2017-04-09T11:36:54-07:00

I'm using the following code trying to change the pixel color:

Code: Select all

//small test: just a really small image to debug and check pixel values

 using (MagickImage spotImage = new MagickImage(@"C:\test\small-test.TIF"))
                spotImage.ColorSpace = ColorSpace.CMYK;
                using (PixelCollection pc = spotImage.GetPixels())
                    foreach (Pixel p in pc)
                        int chan1 = p.GetChannel(0);
                        int chan2 = p.GetChannel(1);
                        int chan3 = p.GetChannel(2);
                        int chan4 = p.GetChannel(3);

                        if (chan1 == chan2 && chan2 == chan3 && chan3 == chan4 && chan1 == 0)
                            p.SetChannel(0, 0);
                            p.SetChannel(1, 100);
                            p.SetChannel(2, 100);
                            p.SetChannel(3, 0);
However, my output image is exactly like the input - no color is changed.
I got this "how to", from the following link:
http://stackoverflow.com/questions/3070 ... magick-net

I also created a few vars after the pc.Set(p) to check if the channels were updated, and they were correctly update to the values i defined.

Is there something i'm missing ? I also checked Object Reference on Visual Studio and what i'm doing seems to be correct.

Thanks in advance.

Post Reply