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:

image

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


in System.Drawing.Color "R", "G" and "B" exist just you have to set the pixels to

Color.FromArgb(r,g,b);

      



it must be something to set pixels in this library, find and do what i said Best wishes

0


source







All Articles