#include "l_bitmap.h"
L_LTKRN_API L_INT L_ResizeBitmap(pBitmapSrc, pDestBitmap, uFlags)
Resizes the image from an existing bitmap, and puts the resized image into a destination bitmap, leaving the original bitmap intact.
Pointer to the bitmap handle referencing the source bitmap.
Pointer to the bitmap handle referencing the destination bitmap to contain the new resized image.
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. |
SIZE_SCALETOGRAY | [0x0008] (Document and Medical Imaging toolkits). Use interpolation to display black and white images using shades of gray when the image is resized. This improves the readability when the image is scaled up or down. The generated image is 8-bit grayscale, so this option should be used only for black and white images. |
SIZE_OLD_RESAMPLE | [0x0010] Use the old resample algorithm from LEADTOOLS 14.5. |
SIZE_PREMULTIPLYALPHA | [0x0020] Premultiply the alpha channel values when performing resize. |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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
Win32, x64, Linux.
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.
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_ResizeBitmap (&TmpBitmap, &LeadBitmap, SIZE_NORMAL);
if(nRet != SUCCESS)
return nRet;
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 0, 0, NULL);
if(nRet != SUCCESS)
return nRet;
/* Free the temporary bitmap */
L_FreeBitmap(&TmpBitmap);
/* Free the resized bitmap */
L_FreeBitmap(&LeadBitmap);
return SUCCESS;
}
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