+ for ( size_t n = 0; n < WXSIZEOF(ColorMap); n++)
+ {
+ ColorMap[n].to = ::GetSysColor(ColorMap[n].to);
+ }
+
+ HBITMAP hbmOld;
+ HDC hdcMem = CreateCompatibleDC(NULL);
+
+ if (hdcMem)
+ {
+ hbmOld = (HBITMAP) SelectObject(hdcMem, hBitmap);
+
+ for ( int i = 0; i < width; i++ )
+ {
+ for ( int j = 0; j < height; j++ )
+ {
+ COLORREF pixel = ::GetPixel(hdcMem, i, j);
+
+ for ( size_t k = 0; k < WXSIZEOF(ColorMap); k++ )
+ {
+ int distance = abs( GetRValue( pixel ) - GetRValue( ColorMap[k].from )) ;
+ distance = max( distance , abs(GetGValue(pixel ) - GetGValue( ColorMap[k].from ))) ;
+ distance = max( distance , abs(GetBValue(pixel ) - GetBValue( ColorMap[k].from ))) ;
+ if ( distance < 0x10 )
+ {
+ ::SetPixel(hdcMem, i, j, ColorMap[k].to);
+ break;
+ }
+ }
+ }
+ }
+
+
+ SelectObject(hdcMem, hbmOld);
+ DeleteObject(hdcMem);
+ }