Replaces existing alpha channel data or creates new alpha channel data in the destination bitmap.


#include "l_bitmap.h"

L_LTKRN_API L_INT L_SetBitmapAlphaValues(pBitmap, uAlpha)



Points to the destination bitmap handle, which references the bitmap where the alpha channel data will be updated or added.

L_UINT16 uAlpha

Value which will be used to create or replace the alpha channel data. The entire alpha channel will be filled with this value.


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


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.

Typically, an alpha channel contains a mask that is used for transparency. This function, together with L_GetBitmapAlpha and the LEADTOOLS region processing functions, lets you use the alpha channel to implement transparency.

Only 16-, 32- and 64-bit images can have an alpha channel. If pBitmap references a bitmap of any other color resolution, this function converts the pBitmap bitmap to 32-bit before it replaces the alpha channel. (If you want 16-bit, you should change it using L_ColorResBitmap, if necessary, before calling this function.)

If pBitmap is 48-bit, it will be converted to 64-bit and then have the alpha information added to it.

Required DLLs and Libraries


Win32, x64, Linux.

See Also




This example fills the Alpha Channel with a specified value.

L_INT SetBitmapAlphaValuesExample() 
   L_INT nRet; 
   BITMAPHANDLE   MainBitmap;           /* Main bitmap */ 
   L_UINT16       uAlpha=0xFFFF;        /* Alpha channel value */ 
   /* Load a bitmap at 32 bits per pixel */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("Image1.cmp")), &MainBitmap, sizeof(BITMAPHANDLE), 32, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Update the alpha channel in the bitmap */ 
   nRet = L_SetBitmapAlphaValues(&MainBitmap, uAlpha); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Save the bitmap at 32 bits per pixel to keep the alpha channel */ 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.PNG")), &MainBitmap, FILE_PNG, 24, 0, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Free the bitmap */ 
   return SUCCESS; 

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

LEADTOOLS Raster Imaging C API Help

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