L_SetWMFResolution

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SetWMFResolution(nXResolution, nYResolution)

L_INT nXResolution;

horizontal resolution value

L_INT nYResolution;

vertical resolution value

Sets the DPI (dots per inch) value that LEADTOOLS uses when loading WMF/EMF files. By default, the value is 0.

Parameter Description
nXResolution 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.
nYResolution 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.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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:

1.

Call L_SetWMFResolution with nXResolution and nYResolution set to 0.

2.

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:

1.

Call L_SetWMFResolution with nXResolution and nYResolution set to 0.

2.

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.

3.

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.

4.

Call L_SetWMFResolution to set the desired resolution.

5.

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.

Note:

More options are available in the LOADFILEOPTION structure.

Required DLLs and Libraries

LTFIL
File format DLLs

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:

L_FileInfo, L_FileInfoMemory, L_ReadFileComment, L_GetPCDResolution, L_SetPCDResolution, L_GetWMFResolution, L_SetLoadInfoCallback, L_GetComment, L_DeleteComment, L_SetComment, L_2DGetViewMode, L_2DGetViewPort, L_2DSetViewMode, L_2DSetView Port, L_ReadFileComments

Topics:

Raster Image Functions: Input and Output

 

Loading and Saving Images

For a list of functions that utilize the LOADFILEOPTION or SAVEFILEOPTION structures, refer to Functions Utilizing the LOADFILEOPTION or SAVEFILEOPTION structures.

Example

This example loads a WMF image at the resolution needed to fit the width of the current window.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
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 Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help