How do I change the pixel color to use Magick.NET?
How to change pixel color in image use lib Magick.NET. I am using 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 in the output image, the pixel color is not red.
Example:
Why isn't the color of the numbers red?
+3
source to share
2 answers
In 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 pc.Set call will be executed automatically and your example above will work.
+1
source to share