#include "l_bitmap.h"
L_LTFIL_API L_INT L_SetWMFResolution(nXResolution, nYResolution)
Sets the DPI (dots per inch) value that LEADTOOLS uses when loading WMF/EMF files. By default, the value is 0.
The horizontal resolution value that LEADTOOLS is to use when loading images from WMF files. Possible values are:
Value | Meaning |
---|---|
0 | Load the file at the resolution present in the file. |
Any positive value | Load the file at the corresponding DPI. For example, if this value is 150, load the image at 150 DPI. |
The vertical resolution value that LEADTOOLS is to use when loading images from WMF files. Possible values are:
Value | Meaning |
---|---|
0 | Load the file at the resolution present in the file. |
Any positive value | Load the file at the corresponding DPI. For example, if this value is 150, load the image at 150 DPI. |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
The values that this function sets are valid for the current thread, and you can change the values in the thread only by calling this function again.
WMF files can contain vectored graphics or raster images. LEADTOOLS can load either type, but can save only raster images. The issue of image resolution arises mainly when loading vectored graphics.
LEADTOOLS loads a WMF/EMF file by creating a temporary device context (DC), drawing the vectored graphics (or painting the raster image) in the device context, and converting the resulting device context to a bitmap. Loading an image at some smaller DPI values may yield an image that is smaller, and less detailed, than the original, or, since bitmaps use more memory than vectored graphics, it may yield an image that is too large to handle efficiently.
You can use L_GetWMFResolution and L_SetWMFResolution, along with the L_FileInfo or L_FileInfoMemory function, to manage these image size issues. The following are examples of how you can use these functions:
To load an image at its saved resolution, you can do the following:
Call L_SetWMFResolution with nXResolution
and nYResolution
set to 0.
Call L_LoadBitmap to load the file.
To load an image that will fit a predetermined width (such as the width of your application's client area), you can do the following:
Call L_SetWMFResolution with nXResolution and nYResolution set to 0.
Call L_FileInfo, and in the FILEINFO structure, check the XResolution and Width values to determine the resolution and size of the image stored in the file.
Calculate the necessary resolution to get the desired width. Where the necessary resolution is A, the value from FILEINFO.XResolution is B, the desired width is C, and the value of the FILEINFO.Width field is D, the calculation is as follows: A = B * C / D.
Call L_SetWMFResolution to set the desired resolution.
Call L_LoadBitmap to load the file.
Some WMF/EMF files contain viewport information, which requires a device context of a particular size. LEADTOOLS always loads these files using the resolution specified in the file. In this case, the value specified by L_SetWMFResolution has no effect.
Note:
When saving WMF/EMF files, LEADTOOLS saves the current resolution value in the file.
More options are available in the LOADFILEOPTION structure.
Required DLLs and Libraries
Win32, x64, Linux.
This example loads a WMF image at the resolution needed to fit the width of the current window.
L_INT SetWMFResolutionExample(HWND hWnd,pBITMAPHANDLE LeadBitmap )
{
L_INT nRet;
RECT rClientSize; /* RECT for the current window's client area */
L_INT nWMFResolution; /* WMF resolution */
FILEINFO FileInfo; /* File info structure */
/* Get the RECT for the current window's client area */
GetClientRect(hWnd,&rClientSize);
/* Get the current WMF resolution */
nRet = L_GetWMFResolution(&nWMFResolution, &nWMFResolution);
if(nRet != SUCCESS)
return nRet;
/* Update the FILEINFO structure */
memset(&FileInfo, 0, sizeof(FILEINFO));
FileInfo.uStructSize = sizeof(FileInfo);
nRet = L_FileInfo(MAKE_IMAGE_PATH(TEXT("TEST.WMF")),&FileInfo, sizeof(FILEINFO), 0, NULL);
if(nRet != SUCCESS)
return nRet;
/* Calculate the desired resolution to fit the client width */
nWMFResolution = min((L_INT) ((L_INT32) nWMFResolution * (rClientSize.right - rClientSize.left) / INFOWIDTH(&FileInfo)),
(L_INT) ((L_INT32) nWMFResolution * (rClientSize.bottom - rClientSize.top) / INFOHEIGHT(&FileInfo)) );
/* Set the desired resolution */
nRet = L_SetWMFResolution(nWMFResolution, nWMFResolution);
if(nRet != SUCCESS)
return nRet;
/* Load a bitmap at its own bits per pixel */
if(LeadBitmap->Flags.Allocated)
L_FreeBitmap(LeadBitmap);
nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("TEST.WMF")), LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")),LeadBitmap, FILE_BMP, 24, 0, NULL);
if(nRet != SUCCESS)
return nRet;
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