private void GetRenderer(CIMRenderer renderer, XmlNode node, string outputDir) { XmlNode nd = node.SelectSingleNode("//URI"); string _URIPath = nd.InnerText.Replace("CIMPATH=", ""); string _outPath = System.IO.Path.Combine(outputDir, System.IO.Path.GetDirectoryName(_URIPath)); string _URIFileName = System.IO.Path.GetFileNameWithoutExtension(_URIPath); string _imgPath = System.IO.Path.Combine(_outPath, "img\\" + _URIFileName); string _imgPathRelative = "/img" + _URIFileName; string _imgFullPath = ""; switch (renderer.GetType().Name) { case "CIMSimpleRenderer": var simpleRenderer = renderer as CIMSimpleRenderer; //CIMSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle); //You can generate a swatch for a text symbols also. _imgFullPath = System.IO.Path.Combine(_imgPath, _URIFileName + "_Default.png"); BitmapSource bs_simpleRenderer = SavePicturetoFile3(simpleRenderer.Symbol.Symbol, _imgFullPath); XmlNode nd_simpleRenderer = node.SelectSingleNode("Renderer/Symbol/Symbol"); XmlNode nd2 = nd_simpleRenderer.AppendChild(XmlUtility.CreateTextElement(nd_simpleRenderer, "picture", ToBase64(bs_simpleRenderer, "PNG"))); XmlNode nd5 = nd_simpleRenderer.AppendChild(XmlUtility.CreateTextElement(nd2, "picturePath", _imgPathRelative + _URIFileName + "_Default.png")); bs_simpleRenderer = null; //nd_simpleRenderer.AppendChild(nd2); break; case "CIMUniqueValueRenderer": _imgFullPath = System.IO.Path.Combine(_imgPath, _URIFileName + "_Default.png"); var uniqueValueRenderer = renderer as CIMUniqueValueRenderer; BitmapSource bs_uniqueValueRenderer = SavePicturetoFile3(uniqueValueRenderer.DefaultSymbol.Symbol, _imgFullPath); XmlNode nd_uniqueValueRenderer = node.SelectSingleNode("Renderer/DefaultSymbol/Symbol"); XmlNode nd3 = nd_uniqueValueRenderer.AppendChild(XmlUtility.CreateTextElement(nd_uniqueValueRenderer, "picture", ToBase64(bs_uniqueValueRenderer, "PNG"))); XmlNode nd6 = nd_uniqueValueRenderer.AppendChild(XmlUtility.CreateTextElement(nd3, "picturePath", _imgPathRelative + _URIFileName + "_Default.png")); bs_uniqueValueRenderer = null; foreach (CIMUniqueValueGroup uvg in uniqueValueRenderer.Groups) { foreach (CIMUniqueValueClass uvc in uvg.Classes) { _imgFullPath = System.IO.Path.Combine(_imgPath, _URIFileName + "_" + (string.IsNullOrEmpty(uvc.Label) ? System.IO.Path.GetRandomFileName() : MakeValidFileName(uvc.Label) + ".png")); BitmapSource bs_uniqueValueClass = SavePicturetoFile3(uvc.Symbol.Symbol, _imgFullPath); XmlNode nd_uniqueValueClass = node.SelectSingleNode("//CIMUniqueValueClass[Label='" + uvc.Label + "']"); XmlNode nd4 = nd_uniqueValueClass.AppendChild(XmlUtility.CreateTextElement(nd_uniqueValueClass, "picture", ToBase64(bs_uniqueValueClass, "PNG"))); XmlNode nd7 = nd_uniqueValueClass.AppendChild(XmlUtility.CreateTextElement(nd4, "picturePath", _imgPathRelative + _URIFileName + "_" + (string.IsNullOrEmpty(uvc.Label) ? System.IO.Path.GetRandomFileName() : MakeValidFileName(uvc.Label) + ".png"))); bs_uniqueValueClass = null; } } break; default: break; } }
private ImageSource getSymbolPicture(CIMRenderer renderer) { ImageSource _symbolPicture = null; switch (renderer.GetType().Name) { case "CIMSimpleRenderer": var simpleRenderer = renderer as CIMSimpleRenderer; //CIMSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle); //You can generate a swatch for a text symbols also. var si = new SymbolStyleItem() { Symbol = simpleRenderer.Symbol.Symbol, PatchHeight = 32, PatchWidth = 32 }; _symbolPicture = si.PreviewImage; break; case "CIMUniqueValueRenderer": var uniqueValueRenderer = renderer as CIMUniqueValueRenderer; var si1 = new SymbolStyleItem() { Symbol = uniqueValueRenderer.DefaultSymbol.Symbol, PatchHeight = 32, PatchWidth = 32 }; _symbolPicture = si1.PreviewImage; break; default: break; } return(_symbolPicture); }