C# – How apply Color Lut over bitmap image in c#

cimaging

I am opening different types of images like (8 and 16 bit) and they are (Monocrome, RGB ,palette color).

I have raw pixel data of these images.
I create bitmap like this for 8 bit images.

          //for monocrome images i am passing PixelFormat.Format8bppIndexed.
          //for RGB images i am passing PixelFormat.Format24bppRgb
           PixelFormat format = PixelFormat.Format8bppIndexed;
           Bitmap bmp = new Bitmap(Img_Width, Img_Height,format);

           Rectangle rect = new Rectangle(0, 0, Img_Width, Img_Height);

           //locking the bitmap on memory
           BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format);

           // copy the managed byte array to the bitmap's image data
           Marshal.Copy(rawPixel, 0, bmpData.Scan0, rawPixel.Length);
           bmp.UnlockBits(bmpData);

The problem is that when i draw that bmp image then it differs in color than original.
So is there any way to apply lut (lookup table) on that colored images.

i want any unsafe code because i tried getixel and setPixel and they are very slow.
I also dont want Image.fromSource() methods.

Best Answer

Take a look at the bitmap's Image.Palette property.

Related Topic