LMemoryFile::SaveFileBufferCallBack

Summary

This function is called if the buffer of the LBuffer object used by the LMemoryFile::SaveFileBuffer function is not large enough to accommodate the file in memory. This function gives the user the opportunity to reallocate the buffer to an adequate size.

Syntax

#include "ltwrappr.h"

virtual L_INT LMemoryFile::SaveFileBufferCallBack(pLBuffer, uRequiredSize)

Parameters

LBuffer * pLBuffer

Pointer to an LBuffer object into which the bitmap will be saved. This pointer can be used to increase the size of the buffer of the LBuffer object.

L_SIZE_T uRequiredSize

Minimum buffer size, in bytes, required to save the bitmap or file.

Returns

Value Meaning
SUCCESS The function was successful.
FAILURE An error occurred.

Comments

This callback function is optional, but recommended. If the callback is not used, then the user must provide the LMemoryFile::SaveFileBuffer function with a buffer that is large enough to hold the memory file. If the buffer is not large enough and the callback is not used, LMemoryFile::SaveFileBuffer will fail.

To use this function, the user must derive a new class from the LMemoryFile class and override this function. The use of this callback function must also be enabled by calling LBase::EnableCallBack.

If the callback successfully reallocates the buffer, it should return SUCCESS.

If the callback fails to successfully reallocate the buffer, it should return FAILURE.

This function does not support signed data images, unless they are DICOM images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image that is not a DICOM image is passed to this function.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

// Derive a new class from LMemoryFile and 
// override LMemoryFile::SaveFileBufferCallBack 
class LUserMemoryFileSMB : public LMemoryFile 
{ 
   virtual L_INT SaveFileBufferCallBack(LBuffer * pLBuffer, 
                                        L_SIZE_T  uRequiredSize) 
   { 
      L_TCHAR szMessage[128]; 
      wsprintf(szMessage, TEXT("Initial LEAD buffer size: %d\n"), pLBuffer->GetSize()); 
      wsprintf(szMessage, TEXT("%sThe required size: %d"), szMessage, uRequiredSize); 
 
      MessageBox(NULL, szMessage, TEXT("Buffer Info"), MB_OK); 
 
      // Try to reallocate the LEAD buffer  
      pLBuffer->Unlock(); 
      L_INT nRet = pLBuffer->Reallocate(uRequiredSize); 
       
      if (nRet == SUCCESS) 
         return SUCCESS; 
      else 
         return FAILURE; 
   } 
}; 
 
L_INT LMemoryFile__SaveFileBufferCallBackExample(LBitmapBase & Bitmap) 
{ 
   LUserMemoryFileSMB MemoryFile; 
   LBuffer Buffer(1000);   // 1000 bytes initially 
   L_SIZE_T dwFileSize; 
 
   MemoryFile.SetBitmap(&Bitmap); 
 
   if (!MemoryFile.IsCallBackEnabled()) 
      MemoryFile.EnableCallBack(TRUE); 
 
   return MemoryFile.SaveFileBuffer(&Buffer, 
                                    &dwFileSize, 
                                    FILE_TIF, 
                                    0, 
                                    QS, 
                                    SAVEFILE_FIXEDPALETTE, 
                                    NULL); 
} 
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++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.