L_ChangeBitmapHeight (original) (raw)
Summary
Increases or decreases the allocated height of a bitmap. You can use this function in a callback routine to adjust the allocation when loading an image of unknown height.
Syntax
#include "l_bitmap.h"
L_LTKRN_API L_INT L_ChangeBitmapHeight(pBitmap, nHeight)
Parameters
pBITMAPHANDLE pBitmap
Pointer to the bitmap handle referencing the bitmap to be adjusted.
L_INT nHeight
New height in pixels.
Returns
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Comments
This function updates the fields in the bitmap handle to reflect the change.
Required DLLs and Libraries
- LTKRN
- 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
Topics
- Raster Image Functions: Loading Files
- Raster Image Functions: Redirecting Input and Output
- Raster Image Functions: Input and Output
- Loading and Saving Images
Example
This FILEREADCALLBACK example uses L_ChangeBitmapHeight to ensure that the
final bitmap height is the same as the total number of loaded lines.
This can be especially useful when you are loading fax files and you don’t know how many
lines are in the file. Normally, you know the width of the raw fax files but not the height. So
you can start by allocating a small bitmap and increase its height while decoding the file.
L_UINT TotalLines; /* Total number of loaded lines */
L_INT EXT_CALLBACK LoadImageCB(pFILEINFO pFileInfo,
pBITMAPHANDLE pBitmap,
L_UCHAR* pBuffer,
L_UINT uFlags,
L_INT nRow,
L_INT nLines,
L_VOID* pUserData )
{
UNREFERENCED_PARAMETER(pFileInfo);
UNREFERENCED_PARAMETER(pBuffer);
UNREFERENCED_PARAMETER(uFlags);
UNREFERENCED_PARAMETER(nRow);
UNREFERENCED_PARAMETER(pBitmap);
BITMAPHANDLE *pMyBitmap = (BITMAPHANDLE*)pUserData;
/* Increment the current row by the number of lines in the buffer */
TotalLines += nLines;
/* Set the bitmap height to the total number of lines */
L_AccessBitmap(pMyBitmap);
if( TotalLines > (L_UINT)pMyBitmap->Height )
{
L_ReleaseBitmap(pMyBitmap);
L_ChangeBitmapHeight(pMyBitmap, TotalLines );
L_AccessBitmap(pMyBitmap);
}
L_PutBitmapRow(pMyBitmap, pBuffer, nRow, pMyBitmap->BytesPerLine * nLines);
L_ReleaseBitmap(pMyBitmap);
return( SUCCESS );
}
L_INT ChangeBitmapHeightExample(L_VOID)
{
L_INT nRet;
BITMAPHANDLE LeadBitmap;
BITMAPHANDLE DummyBitmap;
FILEINFO FileInfo;
memset(&FileInfo, 0, sizeof(FILEINFO));
nRet = L_FileInfo(MAKE_IMAGE_PATH(TEXT("OCR1.TIF")), &FileInfo, sizeof(FILEINFO), 0, NULL);
if(nRet != SUCCESS)
return nRet;
/* init and allocate the bitmap, to be 1/2 the actual size of the image */
L_InitBitmap(&LeadBitmap, sizeof(BITMAPHANDLE), FileInfo.Width, FileInfo.Height / 2, FileInfo.BitsPerPixel);
L_AllocateBitmap(&LeadBitmap, TYPE_CONV);
nRet = L_LoadFile(MAKE_IMAGE_PATH(TEXT("OCR1.TIF")), &DummyBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, 0, LoadImageCB, (L_VOID*)&LeadBitmap, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
L_FreeBitmap(&LeadBitmap);
L_FreeBitmap(&DummyBitmap);
return nRet;
}
LEADTOOLS Raster Imaging C API Help