Error processing SSI file
LEADTOOLS Forms (Leadtools.Forms.DocumentWriters assembly)

Show in webframe

UpdateMetaFileResolution Method








Handle to the source EMF
New horizontal resolution
New vertical resolution
Changes the resolution of an existing Windows Enhanced Metafile (EMF).
Syntax
public static IntPtr UpdateMetaFileResolution( 
   IntPtr emfHandle,
   int xResolution,
   int yResolution
)
'Declaration
 
Public Shared Function UpdateMetaFileResolution( _
   ByVal emfHandle As IntPtr, _
   ByVal xResolution As Integer, _
   ByVal yResolution As Integer _
) As IntPtr
'Usage
 
Dim emfHandle As IntPtr
Dim xResolution As Integer
Dim yResolution As Integer
Dim value As IntPtr
 
value = DocumentWriter.UpdateMetaFileResolution(emfHandle, xResolution, yResolution)
public static IntPtr UpdateMetaFileResolution( 
   IntPtr emfHandle,
   int xResolution,
   int yResolution
)
 function Leadtools.Forms.DocumentWriters.DocumentWriter.UpdateMetaFileResolution( 
   emfHandle ,
   xResolution ,
   yResolution 
)
public:
static IntPtr UpdateMetaFileResolution( 
   IntPtr emfHandle,
   int xResolution,
   int yResolution
) 

Parameters

emfHandle
Handle to the source EMF
xResolution
New horizontal resolution
yResolution
New vertical resolution

Return Value

A handle to the modified Windows Enhanced Metafile (EMF).
Remarks

This method is especially helpful in case you use the CreateEnhMetaFile Windows API when generating the EMF handle. For example, requirement is to create an EMF with 8.5 by 11 inches at 300 DPI. With CreateEnhMetaFile, the resolution of the generated EMF is the same as the resolution of the reference HDC. Since it is impractical to find an HDC with resolution equal to the desired one, you can use UpdateMetaFileResolution to accomplish this. Here is an example:


            const int resolution = 300;
            // Calculate the width in pixels:
            int widthInPixels = (int)(8.5 * resolution);
            int heightInPixels = (int)(11.0 * resolution);
            Win32.RECT rc = new Win32.RECT();
            rc.left = 0;
            rc.top = 0;
            rc.right = widthInPixels;
            rc.bottom = heightInPixels;
            IntPtr hdc = Win32.CreateEnhMetaFile(IntPtr.Zero, IntPtr.Zero, rc, IntPtr.Zero);
            IntPtr hEmfTemp = Win32.CloseEnhMetaFile(hdc);
            // hEmfTemp has the same resolution as the screen, change it to the desired one
            IntPtr hEmf;
            hEmf = DocumentWriter.UpdateMetaFileResolution(hEmfTemp, resolution, resolution);
            Win32.DeleteEnhMetaFile(hEmfTemp);
            // hEmf now is 8.5 by 11 at 300
            

If xResolution or yResolution is 0, then the original resolution of the EMF handle will be used. If either xResolution or yResolution is equal to -1, then the aspect ratio for original EMF handle will be maintained and the positive value for either xResolution or yResolution will be used as the resolution (DPI) value for the modified emf handle.

Note that xResolution and yResolution cannot be both less than zero.

Example

This example will load an Enhanced Metafile from disk and then change its resolution to 200 by 200 dots per inch.

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Forms.Ocr

Private Shared Sub ShowMetaFileDimension(hemf As IntPtr)
   ' Use System.Drawing.Imaging.Metafile to load the EMF and get its information
   Using metafile As New System.Drawing.Imaging.Metafile(hemf, False)
      Console.WriteLine("Size: {0} by {1} pixels", metafile.Width, metafile.Height)
      Console.WriteLine("Resolution: {0} by {1} pixels/inch", metafile.HorizontalResolution, metafile.VerticalResolution)
   End Using
End Sub
'''/ Windows API
<DllImport("gdi32")> _
Private Shared Function GetEnhMetaFile(lpszMetaFile As String) As IntPtr
End Function
<DllImport("gdi32")> _
Private Shared Function DeleteEnhMetaFile(hemf As IntPtr) As Integer
End Function

      
Public Sub ChangeMetaFileResolutionExample()
   ' Load the original meta file
   Dim hemf As IntPtr = GetEnhMetaFile(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf"))

   ' Show the dimension
   Console.WriteLine("Original EMF dimension:")
   ShowMetaFileDimension(hemf)

   ' Change the resolution to be 200 by 200 dots/inch
   Dim hemfDest As IntPtr = DocumentWriter.UpdateMetaFileResolution(hemf, 200, 200)

   ' No need for the original handle anymore
   DeleteEnhMetaFile(hemf)

   Console.WriteLine("New EMF dimension:")
   ShowMetaFileDimension(hemfDest)

   DeleteEnhMetaFile(hemfDest)
End Sub
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms.Ocr;

private static void ShowMetaFileDimension(IntPtr hemf)
{
   // Use System.Drawing.Imaging.Metafile to load the EMF and get its information
   using (var metafile = new System.Drawing.Imaging.Metafile(hemf, false))
   {
      Console.WriteLine("Size: {0} by {1} pixels", metafile.Width, metafile.Height);
      Console.WriteLine("Resolution: {0} by {1} pixels/inch", metafile.HorizontalResolution, metafile.VerticalResolution);
   }
}
//// Windows API
[DllImport("gdi32")]
private extern static IntPtr GetEnhMetaFile(string lpszMetaFile);
[DllImport("gdi32")]
private extern static int DeleteEnhMetaFile(IntPtr hemf);

      
public void ChangeMetaFileResolutionExample()
{
   // Load the original meta file
   var hemf = GetEnhMetaFile(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.emf"));

   // Show the dimension
   Console.WriteLine("Original EMF dimension:");
   ShowMetaFileDimension(hemf);

   // Change the resolution to be 200 by 200 dots/inch
   var hemfDest = DocumentWriter.UpdateMetaFileResolution(hemf, 200, 200);

   // No need for the original handle anymore
   DeleteEnhMetaFile(hemf);

   Console.WriteLine("New EMF dimension:");
   ShowMetaFileDimension(hemfDest);

   DeleteEnhMetaFile(hemfDest);
}
Requirements

Target Platforms

See Also

Reference

DocumentWriter Class
DocumentWriter Members
DocumentWriter Class
DocumentFormat Enumeration
Programming with LEADTOOLS Document Writers
Files to be Included with Your Application
Unlocking Special LEAD Features

Error processing SSI file
Leadtools.Forms.DocumentWriters requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features