Ab2d.ReaderWmf - metafile importer

Ab2d.ReaderWmf is a class library that can be used to read Windows metafiles (wmf) and also Enhanced Metafiles (emf) in runtime and import its elements into WPF's Viewbox.

Note that Ab2d.ReaderWmf cannot be used in Silverlight applications - but can be used in XBAP Web Browser application. For Silverlight use Paste2Xaml and select export as Silverlight xaml in the export options.

The library is used by Paste2Xaml application. It can also be used in any other application which is using metafile cliparts. With ReaderWmf library there is no need to convert them into xaml - metafiles can be simple imported at runtime when needed.


Read Windows metafiles (wmf) or Enhanced Metafiles (emf) file in XAML:

  • In project add reference to Ab2d.ReaderWmf
  • Add namespace definition into root xaml element (for example Window):
    xmlns:ab2d="clr-namespace:Ab2d;assembly=Ab2d.ReaderWmf"
  • Use WmfViewbox to read a metafile file - set Source property to metafile location.

Source property can be uses just as Source of the Image control. Depending on the location and metafile build action use of of the following patterns to load the file (usage of ReaderWmf is very similar to ReaderSvg - see also ReaderSvgSample that is included in the download):

Location: samples folder in project, Build Action: Content
<ab2d:WmfViewbox Source="samples/myClipart.emf"/>

Location: samples folder in project, Build Action: Resource - embedded into assembly
<ab2d:WmfViewbox Source="samples/myClipart.emf"/>

Location: internet, Build Action: not included in project
<ab2d:WmfViewbox Source="http://www.myweb.com/images/myClipart.emf"/>

Location: loose emf file on the local disk, Build Action: not included in the project
<ab2d:WmfViewbox Source="c:\temp\myClipart.emf"/>

Location: loose emf file in the application directory, Build Action: not included in the project
<ab2d:WmfViewbox Source="pack://siteoforigin:,,,/myClipart.emf"/>


Read metafile file in code:

It is possible to create an instance of WmfViewbox in code:

Ab2d.WmfViewbox myButton = new Ab2d.WmfViewbox();
myButton.Source = new Uri("loadButton.emf");
myButtonsStackPanel.Children.Add(myButton);

It is also possible to use ReaderWmf directly:

Viewbox myButton = Ab2d.ReaderWmf.Instance.Read("c:\\temp\\openButton.emf");
myButtonsStackPanel.Children.Add(myButton);

Note that the when using Read method with the file name it must be a real file with full path and not a resource of Uri as with the WmfViewbox's Source property. With Read method it is also possible to read metafile from stream.


Public Properties:

Before reading metafile file you can set the Width and Height properties of ReaderWmf to specify the size of returned Viewbox - if size is not set the size of Element that will host the read Viewbox will be used.

It is also possible to set MinLineWidthFactor to control minimal StrokeThickness of lines. The default value of MinLineWidthFactor is 1 that means that the minimal stroke thickness will be approximately one pixel on the current screen. Bigger value will mean wider lines, smaller will mean thinner lines (for example 0.5 will be only half pixel wide). This is especially useful for metafiles with lots of lines - like metafiles exported from Autocad or other 2D drawing application.

After the metafile file was read you can access the following properties:

LastReadViewbox is a Viewbox element that was created with last Read method.

EmbeddedBitmapImages is a List<BitmapSource> that can be used to get the embedded bitmap images. For example:

XAML: <ab2d:WmfViewbox Name="MyClipartViewbox" Source="MyClipArt.emf"/>
code: Image firstEmbeddedImage = new Image();
firstEmbeddedImage.Source = MyClipartViewbox.InnerReaderWmf.EmbeddedBitmapImages[0];

or if ReaderSvg is used directly:

Ab2d.ReaderWmf myReaderWmf = new Ab2d.ReaderWmf();
Viewbox clipart = myReaderWmf.Read(fileName);
Image firstEmbeddedImage = new Image();
firstEmbeddedImage.Source = myReaderWmf.EmbeddedBitmapImages[0];


New in version 2.0

  • Integrated licensing system - girst commercial version.

New in version 1.4

  • Added support for pen's LineJoin, LineCap and Dash Style.
  • Added support for Arc.
  • Improved placing text in some metafiles.
  • Corrected the width of the lines.
  • Correctly use Polyline and Polygon.

New in version 1.3

  • fixed problems with some wmf files that were imported with some anomalies (lost details).

New in version 1.2

  • Fixed reading some wmf files - especially files exported from Autocad are converted properly now.
  • Added MinLineWidthFactor property - useful for metafiles with lots of lines. With the property it is possible to adjust thickness of the lines.
  • Added EmbeddedBitmapImages property that replaced the obsolete MetafileImages (because of misunderstanding of the property)
  • Added support for reading pixels (individual points) from metafiles - they are converted to Ellipse elements with the specified radius.

New in version 1.1

  • Added WmfViewbox control.
  • Added support for PenStyle (solid, dash, dashDot, dashDotDot, null)
  • Added EmbeddedBitmapImages property that replaced the obsolete MetafileImages (because of misunderstanding the property)
  • Fixed StrokeEndLineCap and StrokeStartLineCap when none (set to round) or only LineJoin is defined (set to the same as LineJoin)

 


ReaderWmf can be downloaded with Paste2Xaml application:




DOWNLOAD All Ab2d tools, libraries and samples (1.13 MB) [8 Jul 2008]
(Paste2Xaml, ViewerSvg, Ab2d.ReaderWmf, Ab2d.ReaderSvg, ReaderSvg sample app.)


System requirements:
Windows XP, Windows Vista (recommended)
.Net Framework 3.0 (also works with 3.5)
Visual Studio 2005 (can be imported into VS 2008) - for samples

 

Note: Subscribe to RSS feed or submit your email on downloads section to be informed about new content on the site.

Copyright © 2007 by Andrej Benedik. All Rights Reserved.