L_SaveBitmapWithLayers

Summary

Saves an image contained in a bitmap to a file, along with the specified layers.

Syntax

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveBitmapWithLayers(pszFile, pBitmap, nFormat, nBitsPerPixel, nQFactor, hLayers, pLayerInfo, nLayers, pSaveOptions)

Parameters

L_TCHAR* pszFile

Character string containing the output file name.

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap that holds the image data.

L_INT nFormat

Output file format. Currently, only PSD (FILE_PSD) files support layers.

L_INT nBitsPerPixel

Resulting file's pixel depth. For color images this can be 24 or 32. For grayscale images this can be 8.

L_INT nQFactor

Reserved for future use. Pass 0.

HBITMAPLIST hLayers

Handle to the bitmap list that contains the layers to save in the output file. The layers should have the same bits per pixel as the file. Every bitmap in the list will be saved as a layer. The first bitmap in the list will be interpreted as the first layer. The bitmaps in the bitmap list must have the same bits per pixel as specified in nBitsPerPixel.

pLAYERINFO pLayerInfo

Pointer to an optional array of LAYERINFO structures. If this is NULL, then each layer will start at (0, 0) and will have the same size as the image. If this is not NULL, then the layer information for each layer in hLayers will be stored here. The number of LAYERINFO structures is given in nLayers.

L_INT nLayers

The number of LAYERINFO structures in the pLayerInfo array. This value should be the same as the number of bitmaps in the hLayers bitmap list. This parameter is used only if pLayerInfo is not NULL.

pSAVEFILEOPTION pSaveOptions

Pointer to optional extended save options. Pass NULL to use the default save options.

Returns

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

Comments

Currently, only the PSD format supports layers.

This function supports signed data images, but only DICOM and TIFF formats support signed data. This function will return an error code if you attempt to save a signed image to a format other than DICOM or TIFF.

If the bitmap has a region, the region stored in the bitmap will be saved, if the image is saved as one of the TIFF file formats.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example saves a bitmap and 3 layers

L_INT SaveBitmapWithLayersExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE Bitmap;  
   HBITMAPLIST hLayers; 
   L_INT nLayers = 3; 
   L_INT i; 
   LAYERINFO layerInfo[3]; 
 
   memset(layerInfo, 0, sizeof(layerInfo)); 
   for (i=0; i<3; i++) 
   { 
      ZeroMemory(&layerInfo[i], sizeof(LAYERINFO)); 
       layerInfo[i].uStructSize = sizeof(LAYERINFO); 
       layerInfo[i].nLayerLeft = 0; 
       layerInfo[i].nLayerTop = 0; 
       layerInfo[i].uOpacity = 255; 
       layerInfo[i].uClipping =0; 
       memcpy(layerInfo[i].szBlendModeKey, "norm", 4); 
       layerInfo[i].pMaskBitmap = NULL; 
   } 
   nRet = L_CreateBitmapList(&hLayers); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* load the bitmap for the first layer */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH("layer0.bmp"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
   { 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
   nRet = L_InsertBitmapListItem(hLayers,(L_UINT)-1, &Bitmap); 
   if(nRet != SUCCESS) 
   { 
      L_FreeBitmap (&Bitmap); 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
 
   /* load the bitmap for the second layer */ 
   /* Note that I do not free the bitmap I just loaded because I inserted it in the list */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH("layer1.bmp"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
   { 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
   nRet = L_InsertBitmapListItem(hLayers, (L_UINT)-1, &Bitmap); 
   if(nRet != SUCCESS) 
   { 
      L_FreeBitmap (&Bitmap); 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
 
   /* load the bitmap for the third layer */ 
   /* Note that I do not free the bitmap I just loaded because I inserted it in the list */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH("layer2.bmp"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
   { 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
   nRet = L_InsertBitmapListItem(hLayers, (L_UINT)-1, &Bitmap); 
   if(nRet != SUCCESS) 
   { 
      L_FreeBitmap (&Bitmap); 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
 
   /* Load the bitmap that is made up of all the layers */ 
   memset(&Bitmap, 0, sizeof(Bitmap)); 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH("ULAY1.BMP"), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
   { 
      L_DestroyBitmapList(hLayers); 
      return nRet; 
   } 
 
   /* Save this bitmap and all the layers */ 
   nRet = L_SaveBitmapWithLayers(MAKE_IMAGE_PATH("Out_image.psd"), &Bitmap, FILE_PSD, 0, 0, hLayers, layerInfo, nLayers, NULL); 
 
   /* Free the bitmap */ 
   if(Bitmap.Flags.Allocated) 
      L_FreeBitmap (&Bitmap); 
 
   /* Free the layers bitmap list and all the bitmaps contained in it */ 
   L_DestroyBitmapList(hLayers); 
 
   return nRet; 
} 

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.