L_SetBitmapPalette

#include "l_bitmap.h"

L_LTKRN_API L_INT L_SetBitmapPalette(pBitmap, hPalette)

Replaces the specified bitmaps palette.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap whose palette is to be changed.

L_HPALETTE hPalette

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

Returns

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

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

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 C API DeleteObject when it is no longer needed.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example loads a bitmap, and changes its palette.

#pragma pack(1) 
typedef struct tagLOG256PALETTE 
{ 
   L_UINT16       palVersion; 
   L_UINT16       palNumEntries; 
   PALETTEENTRY   palPalEntry[256]; 
} LOG256PALETTE; 
#pragma pack() 
 
L_INT SetBitmapPaletteExample(L_VOID) 
{ 
   L_INT nRet; 
   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. */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("Master.JPG")), &LeadBitmap, sizeof(BITMAPHANDLE), 8, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* create a grayscale palette */ 
   pal.palVersion = 0x300; 
   pal.palNumEntries = 256; 
   for(u=0; u<256; u++) 
   { 
      pal.palPalEntry[u].peRed   = (byte) u; 
      pal.palPalEntry[u].peGreen = (byte) u; 
      pal.palPalEntry[u].peBlue  = (byte) u; 
      pal.palPalEntry[u].peFlags = 0; 
   } 
   hPalette = CreatePalette((LPLOGPALETTE) &pal); 
 
   /* update the palette */ 
   nRet = L_SetBitmapPalette(&LeadBitmap, hPalette); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* save the image */ 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.bmp")), &LeadBitmap, FILE_BMP , 0, 0, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Free the resized bitmap */ 
   L_FreeBitmap(&LeadBitmap); 
   /* Delete the Palette */ 
   DeleteObject(hPalette); 
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C API Help