Gets the transparency data used by LEADTOOLS when loading PNG files.
#include "l_bitmap.h"
L_LTFIL_API L_UINT L_GetPNGTRNS (pData)
Pointer to a buffer to be updated with the transparency data used when loading PNG files.
| Value | Meaning |
|---|---|
| 0 or > 1 | The length of the data buffer. |
| < 1 | An error occurred. Refer to Return Codes. |
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.
Win32, x64, Linux.
This example gets PNG transparency data
L_INT GetPNGTRNSExample(L_VOID){L_INT nRet;BITMAPHANDLE Bitmap;// Load an image with or without transparencynRet = L_LoadBitmap(MAKE_IMAGE_PATH("LittleGFlyingAlpha.png"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);if( nRet != SUCCESS)return nRet;Bitmap.Flags.Transparency = TRUE;//Get the PNG transparency dataL_UCHAR* pData = NULL;//Allocate memory for the transparency data bufferpData = (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 transparencynRet = L_GetPNGTRNS(pData);if(nRet == 0){OutputDebugString(L_TEXT("No transparencey found!\n"));}//print out the transparency loaded from PNGL_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 paletteif (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 outfor (int i = 0; i < 256; i+=4){// every four colors are 100%, 75%, 50%, and 0% transparentpData[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 filenRet = L_SetPNGTRNS(pData, 256);free(pData);if(nRet != SUCCESS){L_FreeBitmap(&Bitmap);return nRet;}nRet = L_SaveBitmap(MAKE_IMAGE_PATH("output.png"), &Bitmap, FILE_PNG, 8, 0, NULL);L_FreeBitmap(&Bitmap);return nRet;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
