Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
#include "l_bitmap.h"
L_LTKRN_API L_INT L_ResizeBitmap(pBitmapSrc, pDestBitmap, uFlags)
pBITMAPHANDLE pBitmapSrc; |
/* pointer to the source bitmap handle */ |
pBITMAPHANDLE pDestBitmap; |
/* pointer to the destination bitmap handle */ |
L_UINT uFlags; |
/* flags that determine resizing options */ |
Resizes the image from an existing bitmap, and puts the resized image into a destination bitmap, leaving the original bitmap intact.
Parameter |
Description |
|
pBitmapSrc |
Pointer to the bitmap handle referencing the source bitmap. |
|
pDestBitmap |
Pointer to the bitmap handle referencing the destination bitmap to contain the new resized image. |
|
uFlags |
Flags that determine resizing options. Possible values are: |
|
|
Value |
Meaning |
|
SIZE_NORMAL |
[0x0000] Resize normally. |
|
SIZE_FAVORBLACK |
[0x0001] (Document and Medical Imaging toolkits) Preserve black objects when making the image smaller. This option affects only 1-bit, black-and-white images, where it prevents the disappearance of thin lines. You can use a bitwise OR ( | ) to combine this flag with another one. For example, SIZE_RESAMPLE | SIZE_FAVORBLACK causes color images to be resampled, but applies the favor-black option to 1-bit, black-and-white images. |
|
SIZE_RESAMPLE |
[0x0002] Use linear interpolation and averaging to produce a higher-quality image. |
|
SIZE_BICUBIC |
[0x0004] Use bicubic interpolation and averaging to produce a higher quality image. This is slower than SIZE_RESAMPLE. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
You are responsible for allocating enough storage for the destination bitmap. If only one copy is desired, use the L_SizeBitmap function instead of this one.
If you are working with an 8-bit or less image, before calling this function, you must ensure that both bitmap handles refer to the same palette. To do so, you can use the L_CopyBitmapPalette function to duplicate the palette as follows:
L_CopyBitmapPalette(&DestinationBitmap, &SourceBitmap.hPalette);
To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.
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.
See Also
Example
For complete sample code, refer to the FEATURE1 example. This example loads a temporary bitmap, and uses L_ResizeBitmap to create a new bitmap half the size of the original. The example also demonstrates low-level functions for initializing and allocating a bitmap. The same tasks can be done more efficiently with high-level functions. Note that the result is not very good because we resize a dithered image.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName L_INT ResizeBitmapExample (L_VOID) { L_INT nRet; BITMAPHANDLE LeadBitmap; /* Bitmap handle for the final image */ BITMAPHANDLE TmpBitmap; /* Bitmap handle for the initial image */ L_INT NewWidth, NewHeight; /* Resize dimensions */ /* Load the temporary bitmap at 8 bits per pixel so that we can demonstrate how to handle its palette. */ nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 8, ORDER_BGR, NULL, NULL); if(nRet != SUCCESS) return nRet; /* Define the dimensions for resizing */ NewWidth = TmpBitmap.Width / 2; NewHeight = TmpBitmap.Height / 2; /* Initialize the new bitmap handle. */ nRet = L_InitBitmap( &LeadBitmap, sizeof(BITMAPHANDLE), NewWidth, NewHeight, TmpBitmap.BitsPerPixel ); if(nRet != SUCCESS) return nRet; /* Allocate the storage to hold the image data. */ nRet = L_AllocateBitmap( &LeadBitmap, TYPE_CONV ); if(nRet != SUCCESS) return nRet; /* Duplicate the palette */ nRet = L_CopyBitmapPalette(&LeadBitmap, &TmpBitmap); if(nRet != SUCCESS) return nRet; /* Set other useful values in the bitmap handle */ LeadBitmap.ViewPerspective = TmpBitmap.ViewPerspective; LeadBitmap.XResolution = TmpBitmap.XResolution; LeadBitmap.YResolution = TmpBitmap.YResolution; LeadBitmap.Order = TmpBitmap.Order; /* Resize TmpBitmap to create LeadBitmap */ nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 0, 0, NULL); if(nRet != SUCCESS) return nRet; nRet = L_ResizeBitmap (&TmpBitmap, &LeadBitmap, SIZE_NORMAL); if(nRet != SUCCESS) return nRet; /* Free the temporary bitmap */ L_FreeBitmap(&TmpBitmap); /* Free the resized bitmap */ L_FreeBitmap(&LeadBitmap); return SUCCESS; }