Example #1
0
        private static void Draw(ReticleDefinition reticle, string baseName, TrajectoryPoint[] trajectory)
        {
            const double svgWidth  = 10;
            double       svgHeight = Math.Round(reticle.Size.Y / reticle.Size.X * svgWidth, 2);

            var canvas     = SvgCanvasFactory.Create("reticle", $"{svgWidth}in", $"{svgHeight}in");
            var controller = new ReticleDrawController(reticle, canvas);

            controller.DrawReticle();
            controller.DrawBulletDropCompensator(trajectory, DistanceUnit.Yard.New(100), false, DistanceUnit.Yard, "black");
            var svg = SvgCanvasFactory.ToSvg(canvas);

            const int pngWidth  = 1024;
            int       pngHeight = (int)((reticle.Size.Y / reticle.Size.X) * pngWidth);

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(svg);
            var      svgDocument = SvgDocument.Open(xmlDocument);
            var      bm          = svgDocument.Draw(pngWidth, pngHeight);
            var      bm1         = new Bitmap(pngWidth, pngHeight);
            Graphics g           = Graphics.FromImage(bm1);

            g.FillRectangle(Brushes.White, 0, 0, pngWidth, pngHeight);
            g.DrawImage(bm, 0, 0);
            bm1.Save($"{baseName}.png", ImageFormat.Png);
            xmlDocument.Save($"{baseName}.svg");

            xmlDocument = new XmlDocument();
            BallisticXmlSerializer serializer = new BallisticXmlSerializer(xmlDocument);

            xmlDocument.AppendChild(serializer.Serialize(reticle));
            xmlDocument.Save($"{baseName}.reticle");
        }
Example #2
0
        private static void Draw(ReticleDefinition reticle, string baseName)
        {
            var canvas     = SvgCanvasFactory.Create("reticle", "2in", "2in");
            var controller = new ReticleDrawController(reticle, canvas);

            controller.DrawReticle();
            var svg = SvgCanvasFactory.ToSvg(canvas);

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(svg);
            var      svgDocument = SvgDocument.Open(xmlDocument);
            var      bm          = svgDocument.Draw(1024, 1024);
            var      bm1         = new Bitmap(1024, 1024);
            Graphics g           = Graphics.FromImage(bm1);

            g.FillRectangle(Brushes.White, 0, 0, 1024, 1024);
            g.DrawImage(bm, 0, 0);
            bm1.Save($"{baseName}.png", ImageFormat.Png);
            xmlDocument.Save($"{baseName}.svg");

            xmlDocument = new XmlDocument();
            BallisticXmlSerializer serializer = new BallisticXmlSerializer(xmlDocument);

            xmlDocument.AppendChild(serializer.Serialize(reticle));
            xmlDocument.Save($"{baseName}.reticle");

            xmlDocument = new XmlDocument();
            xmlDocument.Load($"{baseName}.reticle");
            BallisticXmlDeserializer deserializer = new BallisticXmlDeserializer();

            _ = deserializer.Deserialize <ReticleDefinition>(xmlDocument.DocumentElement);
        }
        public static void BallisticXmlSerialize <T>(this T value, Stream stream)
            where T : class
        {
            var xmlSeralizer = new BallisticXmlSerializer();

            xmlSeralizer.Document.AppendChild(xmlSeralizer.Serialize(value));
            xmlSeralizer.Document.Save(stream);
        }
 internal XmlElement Serialize(object value) => serializer.Serialize(value);