New Ab2d.ReaderWmf support Drawing objects with advanced optimization

by abenedik 5. December 2008 00:45

I am really excited to inform you about new features of the new Ab2d.ReaderWmf v3.0 library.

Previous versions of Ab2d.ReaderWmf read metafiles and returned them as Shapes (Path, Polyline, Ellipse, etc.). This was great when you needed to manipulate separate objects or add some mouse events to objects. This flexibility with Shapes has its cost when complex objects are shown - the performance could be very poor and memory consumption very high.

WPF provides a much more efficient way to show more complex images with Drawing objects - objects that derive from Geometry class - DrawingGeometry, StreamGeometry, etc. The new version of Ab2d.ReaderWmf provides a ReadGeometry method that returns drawing objects (the Read method returns Shapes). And this is not all - it is possible to further optimize the drawing by using resources for similar Pens and Brushes and by combining geometries together..

The following two graphs show how the load time and the memory usage are decreased when optimized Drawing objects are used. Results are based on a complex dwg (AutoCAD) file that was converted to metafile and exported to xaml with Paste2Xaml with different export options.

geometry load time
geometry memory usage

The results show that it is possible that the load time decreases for more than 10 times and the memory usage for more than 5 times. This is especially true for metafile with lots of objects that have same pen or brush. The results are best on files created from AutoCAD or other CAD or vector drawing application. Cliparts and other types of metafiles also have significant performance improvement.

Heavy optimization of course has its side effects. If geometries are be combined, they cannot be manipulated individually. It is possible that with full optimization, some animalied appear on image. Because of this, it is possible to fine tune the optimization with lots of advanced options and find the right balance between usability and performance.

The following two screenshots show the new Paste2Xaml application and its new Export dialog:

Paste2Xaml ExportDialog

And there is more new to show. The next new feature is support for building ResourceDictionaries from many metafiles. ResourceDictionaryWriter class can be used to simplify this job. And to make this even simpler there is also a sample application with full source code that on one side shows how to use the ResourceDictionaryWriter and on the other side provides really easy to use application to create ResourceDictionaries. The following image shows the ResourceDictionaryWriter application:


The list of new features is not over. Here is also a GetXaml method that gets the xaml text of the last read metafile. This method is needed because the WPF's XamlWriter does not correctly write some elements and is also not useful for naming elements and writing ResourceDictionaries.

That is quite a bunch of new features, isn't it?

So to conclude. The new version of Ab2d.ReaderWmf library not only enables you to convert almost any image from almost any vector drawing application into xaml, but also enables you to choose between Shapes and optimized Drawing objects and also enables you to package all those objects into a ResourceDictionary.

The only thing left to say is to invite you to try the 60 days evaluation version. It is available from

Tags: , , ,