Question

I know how to implement them, but what I don't know is whether to apply the transformation pixel by pixel or is there another way to affect the whole image, using a single call, etc?

AFAIK Get.Set Pixel is very slow. I am not sure if they did it this way.

So if it's the grayscale/desaturate filter as a simple case, how would one write it?

Was it helpful?

Solution

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

For examle 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.

OTHER TIPS

In order to achieve an even faster performance, you may want to check out WPF's Pixel Shader Effects implementation, that works with all .NET WPF visual objects, not just images.

Take a look at an article explaining some basic implementation steps for such an effect:

http://bursjootech.blogspot.com/2008/06/grayscale-effect-pixel-shader-effect-in.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top