I have a bitmap which contains a lot of different colors. But I need to make a scheme from this image with 40 colors or less. That's why I need method to reduce quantity of colors in the bitmap palette.
I'm using code below for my app:
using System.Windows.Media.Imaging; //BitmapSource
==================================================
//Create palette of requied color. Pay heed to maxColorCount it
//can have any value, but PixelFormats supports only 2,4,16 and 256 colors.
var myPalette = new BitmapPalette(ConvertBitmap(b) as BitmapSource, 16);
newFormatedBitmapSource.DestinationPalette = myPalette;
//Set PixelFormats
newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed8;
newFormatedBitmapSource.EndInit();
b = BitmapFromSource(newFormatedBitmapSource);
It works, but very often as a result I recieve an image with bright pixels on a mostly solid background of darker colours:
I tried to do it by myself: get nearest 4 or 9 pixels (square) & blend it. Also I tried to reduce bitmap size and "stretch" the bitmap. In the end I was trying to absorb nearest colors. But the best result I got using method above.
That's why I'm looking for better way to reduce quantity of colors in bitmap palette.
P.S. Images were scaled, and I also drew a grid on top of them.
UPDATED:
I tried to use scolorq, but result was the same. Question still relevant.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…