L_GetPNGTRNS

#include "l_bitmap.h"

L_LTFIL_API L_UINT L_GetPNGTRNS (pData)

Gets the transparency data used by LEADTOOLS when loading PNG files.

Parameters

L_UCHAR *pData

Pointer to a buffer to be updated with the transparency data used when loading PNG files.

Returns

Value Meaning
0 or > 1 The length of the data buffer.
< 1 An error occurred. Refer to Return Codes.

Comments

This function supports1-bit to 8-bit PNG images.

To set the transparency data used when saving PNG files, use L_SetPNGTRNS function.

The transparency data obtained by this function is valid for the current thread.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example gets PNG transparency data

L_INT GetPNGTRNSExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE Bitmap; 
 
   // Load an image with or without transparency 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("LittleGFlyingAlpha.png")), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 
   if( nRet != SUCCESS) 
      return nRet; 
 
   Bitmap.Flags.Transparency = TRUE; 
 
   //Get the PNG transparency data 
   L_UCHAR* pData = NULL; 
 
   //Allocate memory for the transparency data buffer 
   pData = (L_UCHAR *)malloc(256 * sizeof(L_UCHAR)); 
   memset(pData, 0, 256 * sizeof(L_UCHAR)); 
 
   // This will likely return 0 if we loaded an image without transparency 
   nRet = L_GetPNGTRNS(pData); 
   if(nRet == 0) 
   { 
      OutputDebugString(L_TEXT("No transparencey found!\n")); 
   } 
 
   //print out the transparency loaded from PNG 
   L_TCHAR msg[200] = L_TEXT(""); 
   for (int i = 0; i < 256; i++) 
   { 
      wsprintf(msg, L_TEXT("pData[%d]: %d\t"), i, pData[i]); 
      OutputDebugString(msg); 
      if (((i+1)%4) == 0) 
         OutputDebugString(L_TEXT("\n")); 
   } 
 
   //print out the palette 
   if (Bitmap.pPalette) 
   for (int i = 0; i < 256; i++) 
   { 
      wsprintf(msg, L_TEXT("pPalette[%d]: %d\t"), i, Bitmap.pPalette[i]); 
      OutputDebugString(msg); 
      if (((i+1)%4) == 0) 
         OutputDebugString(L_TEXT("\n")); 
   } 
 
   //change the alpha values and print out 
   for (int i = 0; i < 256; i+=4) 
   { 
      // every four colors are 100%, 75%, 50%, and 0% transparent 
      pData[i] = 0; 
      pData[i + 1] = 64; 
      pData[i + 2] = 128; 
      pData[i + 3] = 255; 
      wsprintf(msg, L_TEXT("pData[%d]: %d\tpData[%d]: %d\tpData[%d]: %d\tpData[%d]: %d\t\n"), i, pData[i], i + 1, pData[i + 1], i + 2, pData[i + 2], i + 3, pData[i + 3]); 
      OutputDebugString(msg); 
      if (((i+1)%4) == 0) 
         OutputDebugString(L_TEXT("\n")); 
   } 
 
   // Set the transparency data and save the file 
   nRet = L_SetPNGTRNS(pData, 256); 
   free(pData); 
 
   if(nRet != SUCCESS) 
   { 
      L_FreeBitmap(&Bitmap); 
      return nRet; 
   } 
 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("output.png")), &Bitmap, FILE_PNG, 8, 0, NULL); 
   L_FreeBitmap(&Bitmap); 
 
   return nRet; 
} 

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

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.