c# - The best way to reduce quantity of colors in bitmap palette -


I have a bitmap that has many different colors but I have a plan with 40 colors or less from this picture This is the reason why I need to make the method of reducing the amount of color in the bitmap palette.

I am using the code below for my app:

  I am using System.Windows.Media.Imaging; // bitmapsource =============================================== === // Create the desired color palette Note To make maximum calls, this can be any value of //, but the pixel format supports only 2,4,16 and 256 colors. Var myPalette = New Bitmaplabel (ConvertBitMap (B) bitmapSource, 16); New formatted bitmapsource // set pixelformats newformed bitmapsource.nation format = pixelformat.index8; NewFormatedBitmapSource.EndInit (); B = bitmapformsource (newfixed bitmapsource);  

It works, but often do result I get an image with bright pixels on most solid background of dark colors:

I tried to do it myself: get the nearest 4 or 9 pixels (square) & amp; blend it. Apart from this, I tried to reduce the bitmap size and "stretch" the bitmap, in the end I was trying to absorb the closest colors. But the best result I am using above method.

This is the reason why I'm looking for a better way to reduce the amount of colors in the bitmap palette.

The images were enhanced, and I made the grid above them too.

Renewed:

I scolorq , but the result was the same. The question is still relevant.

There is a great app available in source code with C # this applies 8 algorithms and many of it There are options.


Comments