示例#1
0
        public SvgWidget(Stream stream, double scale, int width = -1, int height = -1)
        {
            var root = XElement.Load(stream);

            this.Scale = scale;

            string viewBox = (string)root.Attribute("viewBox");

            if (!string.IsNullOrEmpty(viewBox))
            {
                var segments = viewBox.Split(' ');

                if (width == -1)
                {
                    int.TryParse(segments[2], out width);
                }

                if (height == -1)
                {
                    int.TryParse(segments[3], out height);
                }
            }

            foreach (var elem in root.Elements(svg + "g"))
            {
                ProcTree(elem);
            }

            width  = (int)(width * this.Scale);
            height = (int)(height * this.Scale);

            imageBuffer = new ImageBuffer(width, height);

            this.MinimumSize = new Vector2(width, height);

            var graphics2D = imageBuffer.NewGraphics2D();

            graphics2D.SetTransform(Affine.NewScaling(this.Scale));
            foreach (var item in items)
            {
                graphics2D.Render(item.VertexSource, item.Color);
            }

            imageBuffer.FlipY();

            stream.Dispose();
            //this.source = new PathStorage(svgDString);
        }
示例#2
0
 public ImageBufferImageData(ImageBuffer image, double pixelWidth)
 {
     resizedImage = this.ToResizedGrayscale(image, pixelWidth);
     resizedImage.FlipY();
 }