Whenever you paint an image to a device of 256 colors or less, the current system palette is used. This topic describes how to ensure that the current system palette is the one you want to use.
First, consider that LEADTOOLS gives you the following two choices for painting to a device of 256 colors or less:
A fixed palette (LEAD's fixed palette or the Netscape palette). The fixed palette is the same for any image. It is good to use when more than one image is displayed at the same time and you want all of the images to look good. A fixed palette is always used when painting a high-color or true-color image. The default is the LEAD fixed palette, but you can specify the Netscape palette for 256-color devices.
The bitmap's own palette. This is the best available representation of the image's colors. It may be an optimized palette or a fixed palette, depending on how the image was created.
Generally, the following order of execution ensures that the current system palette is the one you want to use:
Set the display mode to turn on or turn off the fixed palette when painting all images.
Create the paint palette. The L_CreatePaintPalette function returns a handle to the palette that you want to use. If the fixed palette is turned on, this is always the handle to the fixed palette. Otherwise it is the best available palette for the specified image. The following code shows the variable declarations and the function call. (The scope of the variables is application-dependent; they are shown all together here for simplicity.)
HWND hWnd; /* The current window, usually specified in a function parameter */
BITMAPHANDLE LeadBitmap; /* Bitmap handle for the loaded image. */
HPALETTE hpalPaint; /* Paint palette handle. */
HDC hdc; /* Device context */
hdc = GetDC (hWnd);
hpalPaint = L_CreatePaintPalette (hdc, &LeadBitmap);
Select and realize the system palette, using the palette handle returned by the L_CreatePaintPalette function. The following shows the required function calls (with none of the normal housekeeping):
SelectPalette (hdc, hpalPaint, FALSE);
Call one of the LEADTOOLS painting functions. The following example uses RECT variables that are defined elsewhere, as described in the comments:
&rLeadSource, /* Source rectangle */
NULL, /* Default source clip area */
&rLeadDest, /* Destination rectangle */
&ps.rcPaint, /* Destination clipping set by WM_PAINT */
SRCCOPY); /* Normal Paint */
Normally the execution order described above is handled in the code for the windows palette and painting messages: WM_PALETTECHANGED, WM_QUERYNEWPALETTE, and WM_PAINT. The DEMO example example program shows how these can be implemented.
However, in some cases, such as implementing a paint-while-load feature, it is more efficient to create, select, and realize the palette without going through the message processing. For an example, refer to the FILEREADCALLBACK function.
LEADTOOLS provides two functions for duplicating palettes. The L_DupPalette function duplicates a specified Windows palette. The L_DupBitmapPalette function duplicates the Windows palette of a specified bitmap.
Medical Web Viewer .NET
.NET, Java, Android, and iOS/macOS Assemblies
C API/C++ Class Libraries