Converts all bitmaps in a class object's bitmap list from any bits-per-pixel to any bits-per-pixel. You can use this function to create an optimized palette for all bitmaps in the bitmap list.


#include "ltwrappr.h"

virtual L_INT LBitmapList::ColorResItems(nBitsPerPixel, uFlags, pPalette=NULL, hPalette=NULL, uColors=0)


L_INT nBitsPerPixel

The number of bits per pixel to increase or decrease the bitmaps to. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 48, and 64.

L_UINT32 uFlags

Processing options. Note that the palette and dithering options are useful only when the resulting bitmaps require a palette (when they are 8 bits per pixel or less). You can combine values when appropriate by using a bitwise OR ( | ). The following are valid values:

Value Meaning
CRF_FIXEDPALETTE [0x01] Use LEAD's fixed palette.
CRF_OPTIMIZEDPALETTE [0x02] Create an optimized palette.
CRF_NETSCAPEPALETTE [0x40] Use the fixed palette that is employed by Netscape Navigator and by Microsoft Internet Explorer.
CRF_USERPALETTE [0x10] Use the palette specified in the pPalette parameter.
CRF_IDENTITYPALETTE [0x08] Insert the Windows system palette. You can combine this flag with CRF_OPTIMIZEDPALETTE.
CRF_FASTMATCHPALETTE [0x20] Use a predefined table to speed conversion using your own palette. Refer to LBitmapSettings::CreateUserMatchTable.
CRF_BYTEORDERBGR [0x04] Use BGR color order. This flag only has meaning when going to 16 bits per pixel or higher.
CRF_BYTEORDERRGB [0x00] Use RGB color. This flag only has meaning when going to 16 bits per pixel or higher.
CRF_NODITHERING [0x00000000] Use nearest color matching.
CRF_FLOYDSTEINDITHERING [0x00010000] Use Floyd-Steinberg dithering.
CRF_STUCKIDITHERING [0x00020000] Use Stucki dithering.
CRF_BURKESDITHERING [0x00030000] Use Burkes dithering.
CRF_SIERRADITHERING [0x00040000] Use Sierra dithering.
CRF_STEVENSONARCEDITHERING [0x00050000] Use Stevenson Arce dithering.
CRF_JARVISDITHERING [0x00060000] Use Jarvis dithering.
CRF_ORDEREDDITHERING [0x00070000] Use ordered dithering, which is faster but less accurate than other dithering methods.
CRF_CLUSTEREDDITHERING [0x00080000] Use clustered dithering.


The custom palette to use. Specify this parameter as follows:


The custom palette to use. Specify this parameter as follows:

L_UINT uColors

The number of colors in the palette. Pass 0 to get the default (such as 256 for 8 bits per pixel). Otherwise, do one of the following:


Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Required DLLs and Libraries


Win32, x64.

See Also




This example changes the hue of bitmaps in a list, then updates
the paint palette and the target bitmap's palette for animation playback.
When changing the hue, it preserves the transparent color.

L_INT LBitmapList__ColorResItemsExample(HWND hWnd, LBitmapList *pBitmapList, LPRGBQUAD TransparentColor) 
   L_INT nRet; 
   HDC hdc; /* Device context of the current window */ 
   L_UINT i; /* Loop counter */ 
   L_UINT uCount; /* Number of bitmaps in the list */ 
   LBitmap LeadBitmap;   /* Bitmap handle for the target bitmap */ 
   LBitmap TmpBitmap; /* Temporary bitmap for manipulating the list */ 
   HPALETTE hpalPaint; /* Paint palette handle */ 
   /* Change the hue of each bitmap in the list,  
   and restore the transparent color as the last color in the palette */ 
   uCount = pBitmapList->GetItemsCount (); 
   for (i = 0; i < uCount; ++i) 
      nRet =pBitmapList->GetItem (i, &TmpBitmap,sizeof(TmpBitmap)); 
      if(nRet !=SUCCESS) 
         return nRet; 
      nRet =TmpBitmap.ChangeHue(i * 10); 
      if(nRet !=SUCCESS) 
         return nRet; 
      nRet =TmpBitmap.PutColors(255, 1, TransparentColor); 
      if(nRet !=SUCCESS) 
         return nRet; 
      nRet =pBitmapList->SetItem (i, &TmpBitmap); 
      if(nRet !=SUCCESS) 
         return nRet; 
   /* Get an optimized palette for the whole list */ 
   nRet =pBitmapList->ColorResItems (8, CRF_NODITHERING|CRF_OPTIMIZEDPALETTE, NULL, 0); 
   if(nRet !=SUCCESS) 
      return nRet; 
   /* Update the paint palette that is used for playback */ 
   nRet =pBitmapList->GetItem (0, &TmpBitmap,sizeof(TmpBitmap)); 
   if(nRet !=SUCCESS) 
      return nRet; 
   hdc = GetDC (hWnd); 
   hpalPaint = TmpBitmap.CreatePaintPalette (hdc); 
   ReleaseDC (hWnd, hdc); 
   /* Update the target bitmap's background color, based on the new palette */ 
   LeadBitmap.SetPlayBackBackGroundColor (TmpBitmap.TranslateColor (LeadBitmap, LeadBitmap.GetPlayBackBackGroundColor ())); 
   /* Copy the new palette to the target bitmap */ 
   LeadBitmap.SetPalette (TmpBitmap.DupPalette ()); 
   return SUCCESS; 

Help Version 22.0.2023.2.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help