How to change pixel color on the image use the lib Magick.NET. I use the following code:
MagickImage img = new MagickImage(@"d:\TEST\110706M01000509.jpg");
WritablePixelCollection pc = img.GetWritablePixels(100, 100, 50, 50);
foreach (Pixel p in pc)
{
p.SetChannel(0, 255);
p.SetChannel(1, 0);
p.SetChannel(2, 0);
}
pc.Write();
img.Write(@"d:\TEST\110706M01000509_.jpg");
But on the output image the color of the pixels no red.
Example:
Why the color of figures is not red?
In 7.4, the above answers are largely correct, but, the method for getting the pixels is now
magick.GetPixels()
not
magick.GetWritablePixels()
They return IPixelCollection
With the current version of Magick.NET (7.0.0.0014) you will need to do this:
using (WritablePixelCollection pc = img.GetWritablePixels(100, 100, 50, 50))
{
foreach (Pixel p in pc)
{
p.SetChannel(0, 255);
p.SetChannel(1, 0);
p.SetChannel(2, 0);
pc.Set(p) // This will update the PixelCollection
}
}
With Magick.NET 7.0.0.0015 the call to pc.Set will be done automatically and your example above will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With