示例#1
0
        private Quad MeasureDrawing(DPoint[] strokeToRender, double zoom)
        {
            var clipRegion = new Quad(0, 0, 0, 0);

            try
            {
                var pts = strokeToRender;
                if (pts == null || pts.Length < 1)
                {
                    return(clipRegion);
                }

                // get size and color from dictionary, or set default
                var attr = GetPenAttributes(zoom, pts);
                var s    = new CoreIncrementalInkStroke(attr, Matrix3x2.Identity);

                var minX = pts.Min(p => p.X);
                var minY = pts.Min(p => p.Y);

                for (int i = 0; i < pts.Length; i++)
                {
                    var current = pts[i];
                    var zx      = ((current.X - minX) * zoom) + minX;
                    var zy      = ((current.Y - minY) * zoom) + minY;
                    s.AppendInkPoints(new[] {
                        new InkPoint(new Point(zx, zy), (float)current.Pressure)
                    });
                }

                var stroke = s.CreateInkStroke();
                if (stroke == null)
                {
                    throw new Exception("Stroke creation failed");
                }

                var bounds = stroke.BoundingRect;
                clipRegion.X      = (int)minX - (2 * attr.Size.Width);
                clipRegion.Y      = (int)minY - (2 * attr.Size.Width);
                clipRegion.Width  = (int)(bounds.Width + (4 * attr.Size.Width * zoom)) + 2;
                clipRegion.Height = (int)(bounds.Height + (4 * attr.Size.Width * zoom)) + 2;
            }
            catch (Exception ex)
            {
                Logging.WriteLogMessage(ex.ToString());
            }

            return(clipRegion);
        }
示例#2
0
        private void DrawToSession([CanBeNull] CanvasDrawingSession g, DPoint[] strokeToRender, [NotNull] Quad clipRegion, double zoom, bool dim = false)
        {
            try
            {
                var pts = strokeToRender;
                if (pts == null || pts.Length < 1)
                {
                    return;
                }

                // using the ink infrastructure for drawing...
                var strokes = new List <InkStroke>();

                var attr = GetPenAttributes(zoom, pts);
                if (dim)
                {
                    attr.Color = Color.FromArgb(255, 127, 127, 127);
                }
                var s = new CoreIncrementalInkStroke(attr, Matrix3x2.Identity);

                for (int i = 0; i < pts.Length; i++)
                {
                    var current = pts[i];
                    s.AppendInkPoints(new[] {
                        new InkPoint(new Point((current.X - clipRegion.X) * zoom, (current.Y - clipRegion.Y) * zoom), (float)current.Pressure)
                    });
                }

                var stroke = s.CreateInkStroke();
                if (stroke == null)
                {
                    throw new Exception("Stroke creation failed");
                }
                strokes.Add(stroke);
                g?.DrawInk(strokes); // this call can be *very* slow! It's bad when using wide strokes at high zoom levels.
            }
            catch (Exception ex)
            {
                Logging.WriteLogMessage(ex.ToString());
            }
        }