Click or drag to resize
ReaderWmfReadGeometry Method
Reads metafile (emf or wmf) from file or from stream and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.).
Reads metafile (emf or wmf) from file or from stream and returns System.Windows.Controls.Image with elements as Drawings (DrawingGeometry, EllipseGeometry, GlyphRunDrawing etc.).
Overload List
  NameDescription
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.).
Top
Remarks

Drawing objects do not derive from the FrameworkElement class and provide a lighter-weight implementation for rendering shapes, images, and text. Because of this Drawing objects on one side lack support for Layout System, input, and focus, but on the other side have much better performance and lower memory consumption.

Returned Drawing has much better performance as Shapes that are returned with Read method.

If better layout support, input, focus and other functionality is needed use Read method instead that returns elements as Shapes.

It is also possible to optimize the read Drawing objects with the GeometrySettings objects that is passed to the ReadGeometry method.

Examples
The following sample reads the mySample.wmf file into sampleImage:
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;

Image sampleImage = myReader.ReadGeometry(@"c:\mySample.wmf", settings);
The following sample shows how to read metafile from Application's Resource (mySample.emf file is included into the project under cliparts folder and its build action is set to Resource). The metafile is read into Drawing objects with full geometry optimization.
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);
}
Remarks

Drawing objects do not derive from the FrameworkElement class and provide a lighter-weight implementation for rendering shapes, images, and text. Because of this Drawing objects on one side lack support for Layout System, input, and focus, but on the other side have much better performance and lower memory consumption.

Returned Drawing has much better performance as Shapes that are returned with Read method.

If better layout support, input, focus and other functionality is needed use Read method instead that returns elements as Shapes.

It is also possible to optimize the read Drawing objects with the GeometrySettings objects that is passed to the ReadGeometry method.

Examples
The following sample reads the mySample.wmf file into sampleImage:
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;

Image sampleImage = myReader.ReadGeometry(@"c:\mySample.wmf", settings);
The following sample shows how to read metafile from Application's Resource (mySample.emf file is included into the project under cliparts folder and its build action is set to Resource). The metafile is read into Drawing objects with full geometry optimization.
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);
}
See Also