How to process each pixel of the image maximally quickly?

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
User avatar
dlemstra
Posts: 1562
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: How to process each pixel of the image maximally quickly?

Post by dlemstra » 2017-02-21T13:23:05-07:00

You are getting all the pixels for each row. You might want to change your loop into something like this:

Code: Select all

using (PixelCollection pc = img.GetPixels())
{
  int channelsCount = pc.Channels;
  for (int y = 0; y < img.Height; y++)
  {
    var pcv = pc.GetArea(0, y, img.Width, 1);
    for (int x = 0; x < pcv.Length; x += channelsCount)
    {
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Post Reply