我有一个包含许多不同颜色的位图。但我需要用这种图像制作一个40色或更少颜色的方案。这就是为什么我需要方法来减少位图调色板中的颜色数量。
我正在为我的应用使用以下代码:
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);
它可以工作,但很多时候我会在较暗色的大部分背景下接收带有明亮像素的图像:
我试着自己做:最近的4或9像素(方形)&混合它。我还试图减少位图大小并“拉伸”位图。最后我试图吸收最近的颜色。但是我使用上述方法得到的最好结果。
这就是为什么我正在寻找更好的方法来减少位图调色板中的颜色数量。
P.S。图像被缩放,我还在它们上面画了一个网格。
更新:
我尝试使用 scolorq ,但结果是一样的。问题仍然相关。