L_GetPNGTRNS

#include "l_bitmap.h"

L_LTFIL_API L_UINT L_GetPNGTRNS (pData)

L_UCHAR *pData;

pointer to a buffer

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

Parameter

Description

pData

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

Returns

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

LTFIL

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

Win32, x64, Linux.

See Also

Functions:

L_SetPNGTRNS, L_SetBitmapAlpha, L_CreateMaskFromBitmapRgn, L_SetBitmapRgnFromMask

Topics:

Raster Image Functions: Loading Files

 

Loading and Saving Images

 

PNG Files and Transparency

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 20.0.2018.7.30
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help