Click or drag to resize
ReaderWmf Class
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. For usage in xaml see WmfViewbox and WmfDrawing.
Inheritance Hierarchy
SystemObject
  Ab2dReaderWmf

Namespace: Ab2d
Assembly: Ab2d.ReaderWmf (in Ab2d.ReaderWmf.dll) Version: 7.1.5512.1040
Syntax
C#
public class ReaderWmf : IDisposable

The ReaderWmf type exposes the following members.

Constructors
  NameDescription
Public methodReaderWmf
Constructor
Top
Properties
  NameDescription
Public propertyAutoSize
If true (default) the size of main canvas is set from the bounds defined in metafile header. Bounds define the size that is just as big as its containing objects. If false the size is set from Frame size that is defined in metafile header. This is useful for example if you were working on a Letter area and would like to preserve the position of objects inside the Letter.
Public propertyCombineGradientPolygons
Gets or sets a Boolean that specifies if the polygons that are used to create a gradient are combined into one polygon with gradient brush. Default value is true.
Public propertyConvertPatternBrushesToColor
Gets or sets a Boolean that specifies if monocrome pattern brushes are converted into color.
Public propertyCustomContentHeight
Gets or sets the height that is used to set the custom width of the read objects. Default value is 0 that means that the height defined in metafile is used.
Public propertyCustomContentWidth
Gets or sets the width that is used to set the custom width of the read objects. Default value is 0 that means that the width defined in metafile is used.
Public propertyDisableTextScaling
Gets or sets a Boolean that specifies if text scaling is disabled. Default value is false.
Public propertyEmbeddedBitmapImages
Gets list of all bitmap images that are defined in Metafile and cannot be converted to vector elements
Public propertyEmbeddedImagesData
Gets list of images raw data and their image formats.
Public propertyHeight
Gets or sets the Height of the returned Viewbox or Image element.
Public propertyStatic memberCode exampleInstance
Gets static instance of ReaderWmf so you do not need to create your own instance of it.
Public propertyLastReadImage
Gets the lastly read wmf or emf as WPF's Image element (used when ReadGeometry is used, when using Read method see LastReadViewbox)
Public propertyLastReadViewbox
Gets the lastly read wmf or emf as WPF's Viewbox element (used when Read method is used, when using ReadGeometry method see LastReadImage)
Public propertyStatic memberLicenseInfo
License information
Public propertyLimitToScaleCustomTextWidth
Gets or sets a double that specifies at which ratio of custom sized text and its normal size a ScaleTransform is used on TextBlock. This value is only used when ProcessCharacterSpacing is set to true. Default value is 0.03;
Public propertyMetafileImages Obsolete.
Gets list of all bitmap images that are defined in Metafile and cannot be converted to vector elements
Public propertyMetafileUnits
Gets or sets the units in which the matafile objects will be read. The default value is Pixel.
Public propertyMinLineWidthFactor
Advanced users can set this property to control minimal StrokeThickness of lines.
Public propertyProcessCharacterSpacing
Gets or sets a Boolean that specifies if character spacing data from metafile is used to resize text when needed. Default value is true.
Public propertyReadEmfPlusRecords
Gets of sets a Boolean that specifies if emf plus records are read. Default value is true.
Public propertyReadPatternBrushes
Gets or sets a Boolean that specifies if pattern brushes are read. Default value is true.
Public propertyRemoveEmptyTextBlocks
Gets or sets a Boolean that specifies if empty texts are not imported (default value is false).
Public propertyShowDemoTextInEvaluation Obsolete.
ShowDemoTextInEvaluation is not used any more.
Public propertyUsedMinLineWidthFactor
Gets the MinLineWidthFactor that was used when reading metafile.
Public propertyWidth
Gets or sets the Width of the returned Viewbox or Image element.
Top
Methods
  NameDescription
Public methodDispose
Dispose
Public methodGetFromClipboard
Creates metafile from clipboard (if available) and converts it into Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.).
Public methodGetFromHemf
Creates metafile from hemf (handle to metafile) and converts it into Viewbox.
Public methodGetGeometryFromClipboard
Creates metafile from clipboard (if available) and converts it into Viewbox with elements as Shapes (Path, Ellipse, Polyline, etc.) and TextBlocks (for texts).
Public methodGetGeometryFromClipboard(GeometrySettings)
Creates metafile from clipboard (if available) and converts it into Viewbox with elements as Shapes (Path, Ellipse, Polyline, etc.) and TextBlocks (for texts).
Public methodGetGeometryFromHemf
Creates metafile from hemf (handle to metafile) and converts it into Drawing.
Public methodGetSize
Returns the size of the read metafile in the currently used metafile units.
Public methodGetSize(MetafileUnits)
Returns the size of the read metafile in the units specified as the method parameter.
Public methodCode exampleGetXaml
Gets xaml of the last read metafile with the default setting for WPF.
Public methodCode exampleGetXaml(BaseXamlWriterSettings)
Gets xaml of the last read metafile.
Public methodIsClipboardMetafileAvailable
Checks if there is a metafile data available on the clipboard and returns true in this case. Otherwise returns false.
Public methodCode exampleRead(Stream)
Reads metafile (emf or wmf) from stream and returns System.Windows.Controls.Viewbox with elements as Shapes (Path, Ellipse, Polyline, etc.) and TextBlocks (for texts).
Public methodCode exampleRead(String)
Reads metafile (emf or wmf) and returns System.Windows.Controls.Viewbox with elements as Shapes (Path, Ellipse, Polyline, etc.) and TextBlocks (for texts).
Public methodCode exampleReadGeometry(Stream)
Reads metafile (emf or wmf) from fileName and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.) with no geometry optimization.
Public methodCode exampleReadGeometry(String)
Reads metafile (emf or wmf) from fileName and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.) with no geometry optimization.
Public methodCode exampleReadGeometry(Stream, GeometrySettings)
Reads metafile (emf or wmf) from fileName and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.).
Public methodCode exampleReadGeometry(String, GeometrySettings)
Reads metafile (emf or wmf) from fileName and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.).
Public methodTransform
Transform method transforms all the coordinates, sizes and other values in the last read Viewbox with using transformation.
Top
Events
  NameDescription
Public eventProgressChanged
ProgressChanged event can be used to get notifications of how much the metafile has been read.
Top
Fields
  NameDescription
Public fieldResolveBitmapOperation
ResolveBitmapOperation is called when a bitmap should be rendered by an operation that is not supported in WPF (defined in second parameter). The Func can be used to convert the bitmap so it will support the oparation - for example for alpha blending we can convert black to transparent. The second parameter defines the dwRop or blendoperation function defined by metadata - see GDI+ documentation for more info.
Public fieldResolveRasterOperation
ResolveRasterOperation can be used to set a delegate that is called when an unsupported raster operation is used in metafile. ResolveRasterOperation delegate returns a Brush that is used for the unsupported raster operation. If null is returned than the Rectangle will not be created.
Top
Remarks

Ab2d.ReaderWmf class can be used to read Windows metafiles (wmf) and also Enhanced Metafiles (emf).

They can be read as Shapes with Read(String) method or as Drawing objects with ReadGeometry(String, GeometrySettings).

After the file has been read, it is possible to get the xaml of the read Viewbox or Image with GetXaml(BaseXamlWriterSettings) method.

If your application needs images and shapes from many metafiles, it is recommended that they are stored in a ResourceDictionary. To simplify creating ResourceDictionaries a ResourceDictionaryWriter class can be used.

Ab2d.ReaderWmf can be used from code. If you would like to add metafile directly into the xaml you can use WmfViewbox to add metafile as shapes or WmfDrawing to add it as geometry.

Examples

The following example shows the most simple use of ReaderWmf. It loads the mySample metafile and adds it to the myStackPanel.

Viewbox sampleViewbox = Ab2d.ReaderWmf.Instance.Read(@"c:\mySample.wmf");
myStackPanel.Children.Add(sampleViewbox);

The following sample shows how to read metafile from Application's Resource. The ReadGeometry(String, GeometrySettings) reads metafile into Drawing objects and fully optimizes it for best performance.

Image clipartFromResource;
Ab2d.Common.ReaderWmf.GeometrySettings settings;

// gets Drawing objects optimized for best performance
// NOTE: Because of heavy optimization it is possible that some anomalies appear on the image
settings = Ab2d.Common.ReaderWmf.GeometrySettings.FullOptimization;

Uri uri = new Uri("/cliparts/mySample.emf", UriKind.Relative);
using (Stream metafileStream = Application.GetResourceStream(uri).Stream)
{
    clipartFromResource = Ab2d.ReaderWmf.Instance.ReadGeometry(metafileStream, settings);
}

myStackPanel.Children.Add(clipartFromResource);

The following sample reads the mySample.wmf file, gets its xaml for Silverlight and saves it into a file.

string xaml;
Viewbox sampleViewbox;

sampleViewbox = myReader.Read(@"c:\mySample.wmf");
xaml = myReader.GetXaml(new Ab2d.Common.ReaderWmf.SilverlightXamlWriterSettings());

System.IO.File.WriteAllText(@"c:\mySample_for_Silverlight.xaml", xaml);
See Also