Implementing Photoshop Filters in C #

I know how to implement them, but I don’t know whether to apply pixel transform by pixel or is there another way to affect the whole image using one call, etc.?

AFAIK Get.Set Pixel is very slow. I'm not sure if they did it like that.

So, if this is a grayscale / discoloration filter as a simple case, how would I write it?

+3
source share
2 answers

You need to lock the image, and then work with memory directly, bypassing the SetPixel method. See here or even better here

For reference, you can set the blue color to 255 as follows

   BitmapData bmd=bm.LockBits(new Rectangle(0, 0, 10, 10), System.Drawing.Imaging.ImageLockMode.ReadOnly, bm.PixelFormat);
      int PixelSize=4;
      for(int y=0; y<bmd.Height; y++)
      {
        byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
        for(int x=0; x<bmd.Width; x++)
        {
          row[x*PixelSize]=255;
        }
      } // it is copied from the last provided link.
+5

Source: https://habr.com/ru/post/1715481/


All Articles