L_SetBitmapPalette

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_SetBitmapPalette(pBitmap, hPalette)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

HPALETTE hPalette;

/* handle to a Windows GDI palette */

Replaces the specified bitmap’s palette.

Parameter

Description

pBitmap

Pointer to the bitmap whose palette is to be changed.

hPalette

Handle to the Windows GDI palette that will replace the existing bitmap palette.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

The bitmap must be 8-bit or less in order to have a valid palette. The hPalette will be duplicated. The copy of hPalette that is made by this function will be destroyed when the bitmap is freed. You must destroy the original hPalette using the Windows API DeleteObject when it is no longer needed.

Required DLLs and Libraries

LTKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

L_GetFixedPalette, L_ColorResBitmap, L_CreatePaintPalette, L_GetBitmapColors, L_PutBitmapColors, L_DupPalette, L_DupBitmapPalette

Topics:

Raster Image Functions: Displaying ImagesHandling Palette Changes

Example

#pragma pack(1)
typedef struct tagLOG256PALETTE
{
   L_UINT16 palVersion;
   L_UINT16 palNumEntries;
   PALETTEENTRY palPalEntry[256];
} LOG256PALETTE;
#pragma pack()

L_VOID SetBitmapPalette()

{

/* This example loads a bitmap, and changes its palette */

BITMAPHANDLE LeadBitmap; /* Bitmap handle for the final image */

HPALETTE hPalette=NULL;

LOG256PALETTE pal;

L_UINT u;

 

/* Load the bitmap at 8 bits per pixel so that we can demonstrate
how to handle its palette. */
L_LoadBitmap
 (TEXT("d:\\temp\\golf.jpg"), &LeadBitmap, sizeof(BITMAPHANDLE), 8, ORDER_BGR, NULL, NULL);

/* create a grayscale palette */
pal.palVersion = 0x300;
pal.palNumEntries = 256;
for(u=0; u<256; u++)
{
      pal.palPalEntry[u].peRed   = u;
      pal.palPalEntry[u].peGreen = u;
      pal.palPalEntry[u].peBlue  = u;
      pal.palPalEntry[u].peFlags = 0;
}
hPalette = CreatePalette((LPLOGPALETTE) &pal);

/* update the palette */
L_SetBitmapPalette
(&LeadBitmap, hPalette);

/* save the image */
L_SaveBitmap
(TEXT("d:\\temp\\PALETTE.BMP"), &LeadBitmap, FILE_BMP, 0, 0, NULL);

/* Free the resized bitmap */
L_FreeBitmap
(&LeadBitmap);
/* Delete the Palette */
DeleteObject(hPalette);

}