ReaderWmfGetXaml Method (BaseXamlWriterSettings) |
Namespace: Ab2d
public string GetXaml( BaseXamlWriterSettings settings )
Read or ReadGeometry must be called before using GetXaml.
To get xaml for WPF, use Ab2d.Common.ReaderWmf.WpfXamlWriterSettings. For Silverlight use Ab2d.Common.ReaderWmf.SilverlightXamlWriterSettings.
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);
The GetXaml method by default writes image uri-s as "image_0.png", "image_1.jpg", and so on. The default format for the uri is controlled by DefaultImageUriFormatString. With ResolveImagePathDelegate it is possible to control the image uri of each of the used images. The following code reads the metafile, saves the images to disk and creates xaml text with image uri-s that point to saved images.
// Use the code with: // string xamlText = GetXamlWithImages("images_test.emf", @"c:\temp\image_{0}.{1}"); private string GetXamlWithImages(string metaFileName, string imageFormatString) { string xamlText; int imagesCount; Ab2d.ReaderWmf myReaderWmf; Ab2d.Common.ReaderWmf.WpfXamlWriterSettings xamlSettings; // Read the svg file myReaderWmf = new Ab2d.ReaderWmf(); myReaderWmf.Read(metaFileName); if (myReaderWmf.EmbeddedBitmapImages != null) { imagesCount = myReaderWmf.EmbeddedBitmapImages.Count; for (int i = 0; i < imagesCount; i++) { string oneFileName; EmbeddedImageData oneImageData; oneImageData = myReaderWmf.EmbeddedImagesData[i]; oneFileName = string.Format(imageFormatString, i, oneImageData.ImageFileExtention); System.IO.File.WriteAllBytes(oneFileName, oneImageData.Data); } } xamlSettings = new Ab2d.Common.ReaderWmf.WpfXamlWriterSettings(); xamlSettings.DefaultImageUriFormatString = imageFormatString; xamlText = myReaderWmf.GetXaml(xamlSettings); return xamlText; }