예제 #1
0
 void DrawScene(DrawingContext dc) {
   dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Point(50, 18), 12, 12);
   dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 51), 12, 12);
   dc.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 87), 12, 12);
   
   dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 111, 24, 24));
   dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 147, 24, 24));
   dc.DrawRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 184, 24, 24));
   
   dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 237, 24, 24), 5, 5);
   dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 270, 24, 24), 5, 5);
   dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 307, 24, 24), 5, 5);
   
   dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 340), new Point (70, 360));
 }
예제 #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            const int radius = 3;
            var       size   = AdornedElement.DesiredSize;

            var pen = new Pen(Brush, 1);

            pen.Freeze();

            var point = new Point((size.Width / 2) + (radius * 3), radius + 1);

            drawingContext?.DrawEllipse(Brush, pen, point, radius, radius);
        }
예제 #3
0
        private void DrawAnnotations()
        {
            m_BoardVisual.Children.Remove(m_AnnotationVisual);
            m_AnnotationVisual = new DrawingVisual();

            using (DrawingContext dc = m_AnnotationVisual.RenderOpen())
            {
                foreach (var anno in m_AnnotationsList)
                {
                    Stone stone     = m_StoneList.ContainsKey(anno.Position) ? m_StoneList[anno.Position] : Stone.Empty;
                    Pen   annoPen   = (stone != Stone.Empty && stone == Stone.Black) ? m_BlackStoneAnnotationPen : m_WhiteStoneAnnotationPen;
                    Brush annoColor = (stone != Stone.Empty && stone == Stone.Black) ? Brushes.White : Brushes.Black;

                    switch (anno.Type)
                    {
                    case GoBoardAnnotationType.Circle:
                        dc.DrawEllipse(Brushes.Transparent, annoPen, new Point(getPosX(anno.Position.X), getPosY(anno.Position.Y)), m_BoardWidthFactor / 4, m_BoardWidthFactor / 4);
                        break;

                    case GoBoardAnnotationType.Rectangle:
                        dc.DrawRectangle(Brushes.Transparent, annoPen, new Rect(new Point(getPosX(anno.Position.X) - m_BoardWidthFactor / 4, getPosY(anno.Position.Y) - m_BoardHeightFactor / 4), new Size(m_BoardWidthFactor / 2, m_BoardHeightFactor / 2)));
                        break;

                    case GoBoardAnnotationType.Label:
                        FormattedText text = new FormattedText(anno.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, m_BoardTypeface, 8, annoColor);
                        dc.DrawRectangle(stone == Stone.Empty ? m_BoardBrush : Brushes.Transparent, null, new Rect(new Point(getPosX(anno.Position.X) - m_BoardWidthFactor / 4, getPosY(anno.Position.Y) - m_BoardHeightFactor / 4), new Size(m_BoardWidthFactor / 2, m_BoardHeightFactor / 2)));
                        dc.DrawText(text, new Point(getPosX(anno.Position.X) - text.Width / 2, getPosY(anno.Position.Y) - text.Height / 2));
                        break;

                    case GoBoardAnnotationType.Triangle:
                        string first  = getPosX(anno.Position.X) + "," + (getPosY(anno.Position.Y) - 5).ToString().Replace(',', '.');
                        string second = (getPosX(anno.Position.X) - 4).ToString().Replace(',', '.') + "," + (getPosY(anno.Position.Y) + 3).ToString().Replace(',', '.');
                        string third  = (getPosX(anno.Position.X) + 4).ToString().Replace(',', '.') + "," + (getPosY(anno.Position.Y) + 3).ToString().Replace(',', '.');
                        dc.DrawGeometry(Brushes.Transparent, annoPen, Geometry.Parse("M " + first + " L " + second + " L " + third + " Z"));
                        break;

                    default:
                        break;
                    }
                }
            }

            m_BoardVisual.Children.Add(m_AnnotationVisual);
        }
예제 #4
0
        public static void MakePicture(string path, string text)
        {
            BitmapSource bgImage = new BitmapImage(new Uri(path, UriKind.Absolute));

            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();


            drawingContext.DrawImage(bgImage, new Rect(0, 0, bgImage.Width, bgImage.Height));


            //计算签名的位置
            FormattedText signatureTxt = new FormattedText(text,
                                                           System.Globalization.CultureInfo.CurrentCulture,
                                                           System.Windows.FlowDirection.LeftToRight,
                                                           new Typeface(System.Windows.SystemFonts.MessageFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
                                                           50,
                                                           System.Windows.Media.Brushes.White);

            drawingContext.DrawText(signatureTxt, new Point(100, 100));
            drawingContext.DrawEllipse(Brushes.SaddleBrown, null, new Point(100, 100), 100, 100);
            drawingContext.Close();
            drawingContext = null;

            RenderTargetBitmap composeImage = new RenderTargetBitmap(bgImage.PixelWidth, bgImage.PixelHeight, bgImage.DpiX, bgImage.DpiY, PixelFormats.Default);

            composeImage.Render(drawingVisual);
            System.Console.WriteLine("DpiX=" + composeImage.DpiX + ", DpiY=" + composeImage.DpiY);

            //保存图片为png
            FileStream stream = new FileStream(@"d:\111111111111.jpg", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
            //PngBitmapEncoder encoder = new PngBitmapEncoder();
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(composeImage));
            encoder.Save(stream);
            stream.Flush();
            stream.Close();
            composeImage  = null;
            drawingVisual = null;
            bgImage       = null;
            encoder       = null;
            stream        = null;
        }
예제 #5
0
        public static void PaintPlatesAndCoordinates(DrawingContext dc)
        {
            //  画板块
            //  先画inactive 再画active
            foreach (Plate plate in roomPlates)
            {
                if (plate != null)
                {
                    if (!plate.Active)
                    {
                        if (plate == roomPlates[10])
                        {
                            PaintPlate(dc, plate, new Pen(Brushes.Yellow, 3));
                        }
                        else
                        if (plate == roomPlates[0])
                        {
                            PaintPlate(dc, plate, new Pen(Brushes.Green, 3));
                        }
                        else
                        {
                            PaintPlate(dc, plate, InactivePlatePen);
                        }
                    }
                }
            }

            foreach (Plate plate in roomPlates)
            {
                if (plate != null)
                {
                    if (plate.Active)
                    {
                        PaintPlate(dc, plate, ActivePlatePen);
                        plate.Active = false;
                    }
                }
            }

            //  画kinect
            dc.DrawLine(new Pen(Brushes.LightGoldenrodYellow, 2), RoomPointToObservePoint(new SpacePoint(2000, 2000, 0)), RoomPointToObservePoint(new SpacePoint(2000, 2000, 1300)));
            dc.DrawLine(new Pen(Brushes.LightGoldenrodYellow, 2), RoomPointToObservePoint(new SpacePoint(2000, 1997, 1300)), RoomPointToObservePoint(new SpacePoint(2000, 2003, 1300)));
            dc.DrawEllipse(Brushes.LightGoldenrodYellow, new Pen(Brushes.LightGoldenrodYellow, 2), RoomPointToObservePoint(new SpacePoint(2000, 2000, 1306)), 3, 3);
        }
예제 #6
0
        /// <summary>
        /// Draws a body
        /// </summary>
        /// <param name="joints">joints to draw</param>
        /// <param name="jointPoints">translated positions of joints to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        /// <param name="drawingPen">specifies color to draw a specific body</param>
        private void DrawBody(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext drawingContext, Pen drawingPen, Boolean isArm = false)
        {
            if (!isArm)
            {
                // Draw the person's bones
                foreach (var bone in this.personBones)
                {
                    this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
                }
            }
            else
            {
                // Draw the wen arm's bones
                foreach (var bone in this.wenArmBones)
                {
                    this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
                }
            }

            // Draw the joints
            foreach (JointType jointType in joints.Keys)
            {
                if ((personJointsToRender.Contains(jointType) && !isRenderingWholeBody) || isRenderingWholeBody)
                {
                    Brush         drawBrush     = null;
                    TrackingState trackingState = joints[jointType].TrackingState;

                    if (trackingState == TrackingState.Tracked)
                    {
                        drawBrush = this.trackedJointBrush;
                    }
                    else if (trackingState == TrackingState.Inferred)
                    {
                        drawBrush = this.inferredJointBrush;
                    }

                    if (drawBrush != null)
                    {
                        drawingContext.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
                        //Debug.WriteLine("We are drawing the joint "+jointType+" on the screen at "+jointPoints[jointType].X+" and "+jointPoints[jointType].Y);
                    }
                }
            }
        }
예제 #7
0
        private void GambarTulangDanJoint(Skeleton skeleton, DrawingContext kontekGbr)
        {
            myCanvas.Children.Clear();
            this.GambarTulang(skeleton, kontekGbr, JointType.Head, JointType.ShoulderCenter);
            this.GambarTulang(skeleton, kontekGbr, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.GambarTulang(skeleton, kontekGbr, JointType.ShoulderCenter, JointType.Spine);
            this.GambarTulang(skeleton, kontekGbr, JointType.Spine, JointType.HipCenter);
            this.GambarTulang(skeleton, kontekGbr, JointType.HipCenter, JointType.HipLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.HipCenter, JointType.HipRight);

            this.GambarTulang(skeleton, kontekGbr, JointType.ShoulderLeft, JointType.ElbowLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.ElbowLeft, JointType.WristLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.WristLeft, JointType.HandLeft);

            this.GambarTulang(skeleton, kontekGbr, JointType.ShoulderRight, JointType.ElbowRight);
            this.GambarTulang(skeleton, kontekGbr, JointType.ElbowRight, JointType.WristRight);
            this.GambarTulang(skeleton, kontekGbr, JointType.WristRight, JointType.HandRight);

            this.GambarTulang(skeleton, kontekGbr, JointType.HipLeft, JointType.KneeLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.KneeLeft, JointType.AnkleLeft);
            this.GambarTulang(skeleton, kontekGbr, JointType.AnkleLeft, JointType.FootLeft);

            this.GambarTulang(skeleton, kontekGbr, JointType.HipRight, JointType.KneeRight);
            this.GambarTulang(skeleton, kontekGbr, JointType.KneeRight, JointType.AnkleRight);
            this.GambarTulang(skeleton, kontekGbr, JointType.AnkleRight, JointType.FootRight);

            foreach (Joint joint in skeleton.Joints)
            {
                Brush gbrBrush = null;
                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    gbrBrush = this.BrushJointTerjejak;
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    gbrBrush = this.BrushJointSimpul;
                }
                if (gbrBrush != null)
                {
                    kontekGbr.DrawEllipse(gbrBrush, null, this.SkeletonPointToScreen(joint.Position), KetebalanJoint, KetebalanJoint);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Draw the skeleton on the color frame image
        /// </summary>
        public void DrawSkeletonOnColorImage(Skeleton skeleton, ImageSource colorFrameImage, Image image)
        {
            if (null == this.imageSource)
            {
                // Create the drawing group we'll use for drawing
                this.drawingGroup = new DrawingGroup();

                // Create an image source that we can use in our image control
                this.imageSource = new DrawingImage(this.drawingGroup);

                image.Source = this.imageSource;
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                if (colorFrameImage != null)
                {
                    dc.DrawImage(colorFrameImage, new Rect(0, 0, colorFrameImage.Width, colorFrameImage.Height));
                }

                if (skeleton != null)
                {
                    // Draw a transparent background to set the render size
                    // dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        this.DrawBonesAndJoints(skeleton, dc);
                    }
                    else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                    {
                        dc.DrawEllipse(
                            this.centerPointBrush,
                            null,
                            this.SkeletonPointToScreen(skeleton.Position),
                            BodyCenterThickness,
                            BodyCenterThickness);
                    }
                }
            }

            // prevent drawing outside of our render area
            this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
        }
예제 #9
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            var radius = ActualHeight / 2;

            // OUTLINE
            var pen    = new Pen(OutlineBrush, OutlineThickness);
            var center = new Point(ActualWidth / 2, ActualHeight / 2);

            drawingContext.DrawEllipse(null, pen, center, radius, radius);

            //
            var angle = 0.0;

            var slicePoint = new Point(radius, 0);

            foreach (var slice in this.slices)
            {
                var pathGeometry = new PathGeometry();
                var pathFigure   = new PathFigure();
                pathFigure.StartPoint = center;
                pathFigure.IsClosed   = true;

                var lineSegment = new LineSegment(slicePoint, true);
                lineSegment.IsSmoothJoin = true;
                angle += slice.Value;
                var arcSegment = new ArcSegment();
                var endOfArc   = new Point(Math.Cos(angle * Math.PI / 180) * radius + center.X, Math.Sin(angle * Math.PI / 180) * radius + center.Y);
                arcSegment.IsLargeArc     = slice.Value >= 180.0;
                arcSegment.Point          = endOfArc;
                arcSegment.Size           = new Size(radius, radius);
                arcSegment.SweepDirection = SweepDirection.Clockwise;
                arcSegment.IsSmoothJoin   = true;
                pathFigure.Segments.Add(lineSegment);
                pathFigure.Segments.Add(arcSegment);
                pathGeometry.Figures.Add(pathFigure);

                var slicePen = new Pen(GetStrokeBySlice(slice), StrokeThickness);
                drawingContext.DrawGeometry(GetFillBySlice(slice), slicePen, pathGeometry);

                slicePoint = endOfArc;
            }
        }
예제 #10
0
        // Draw the main border
        private void DrawBorder(DrawingContext dc, ref Rect bounds, Thickness thickness, bool isUnitThickness)
        {
            if ((bounds.Width >= 5.0) && (bounds.Height >= 5.0))
            {
                if (!IsRound)
                {
                    if (isUnitThickness)
                    {
                        Pen borderPen = BorderPen;

                        if (borderPen != null)
                        {
                            Rect rect = new Rect(bounds.Left + 0.5,
                                                bounds.Top + 0.5,
                                                bounds.Width - 1.0,
                                                bounds.Height - 1.0);

                            dc.DrawRectangle(null, borderPen, rect);
                        }
                    }
                    else
                    {
                        Brush borderBrush = Border;

                        if (borderBrush != null)
                        {
                            dc.DrawGeometry(borderBrush, null, GenerateBorderGeometry(bounds, thickness));
                        }
                    }
                }
                else // IsRound == true
                {
                     Pen borderPen = BorderPen;

                     if (borderPen != null)
                     {
                         double centerX = bounds.Width * 0.5;
                         double centerY = bounds.Height * 0.5;

                         dc.DrawEllipse(null, borderPen, new Point(centerX, centerY), centerX - 0.5, centerY - 0.5);
                     }
                }
            }
        }
예제 #11
0
        protected override void OnRender(DrawingContext dc)
        {
            Rect rc = new Rect(0, 0, this.ActualWidth, this.ActualHeight);

            LinearGradientBrush gradientOverlay = GetGradientOverlay();
            Brush  glowBrush         = GetGlowBrush();
            Brush  backBrush         = GetBackgroundBrush();
            Brush  borderBrush       = GetBorderBrush();
            Pen    borderPen         = new Pen(borderBrush, BorderWidth);
            double cornerRadiusCache = CornerRadius;

            // draw the highlight as necessary
            if (RenderIsMouseOver)
            {
                Rect   rcGlow   = rc;
                double glowMove = BorderWidth * 2;
                rcGlow.Inflate(glowMove, glowMove);
                glowMove = 0;
                rcGlow.Offset(new Vector(glowMove, glowMove));
                dc.DrawRoundedRectangle(GetOuterGlowBrush(), null, rcGlow, cornerRadiusCache, cornerRadiusCache);
            }

            // we want to clip anything that might errantly draw outside of the smart border control
            dc.PushClip(new RectangleGeometry(rc, cornerRadiusCache, cornerRadiusCache));

            dc.DrawRoundedRectangle(backBrush, borderPen, rc, cornerRadiusCache, cornerRadiusCache);
            dc.DrawRoundedRectangle(gradientOverlay, borderPen, rc, cornerRadiusCache, cornerRadiusCache);

            if (!RenderIsPressed)
            {
                double clipBorderSize = BorderWidth * -4.0;
                Rect   rcClip         = rc;
                rcClip.Offset(clipBorderSize, clipBorderSize);
                rcClip.Inflate(-clipBorderSize, -clipBorderSize);
                dc.PushClip(new RectangleGeometry(rcClip, cornerRadiusCache, cornerRadiusCache));
                dc.DrawEllipse(glowBrush, null, new Point(this.ActualWidth / 2, this.ActualHeight * 0.10), this.ActualWidth * 0.80, this.ActualHeight * 0.40);
                dc.Pop();
            }
            // just draw the border now to make sure it overlaps everything nicely
            dc.DrawRoundedRectangle(null, borderPen, rc, cornerRadiusCache, cornerRadiusCache);

            dc.Pop();
            //base.OnRender(drawingContext);
        }
예제 #12
0
        /// <summary>
        /// 画出单个人的骨骼
        /// </summary>
        /// <param name="body"></param>
        /// <param name="bodyIndex"></param>
        /// <param name="dc"></param>
        public void DrawBody(Body body, int bodyIndex, DrawingContext dc)
        {
            if (!body.IsTracked)
            {
                return;
            }
            this.DrawClippedEdges(body, dc); //画出边框
            //获取骨骼节点的三维坐标
            IReadOnlyDictionary <JointType, Joint> bodyJoints = body.Joints;
            //var bodyJointOrientations = body.JointOrientations;
            CameraSpacePoint positionSpineMid = bodyJoints[JointType.SpineMid].Position;
            double           num       = positionSpineMid.Z;
            double           thickness = BonePenMaxSize / num;
            //设置骨骼的画笔
            Pen boneDrawPen = new Pen(this.BodyBrushes[bodyIndex], thickness);
            //将关节点转换为2D深度(显示)空间
            Dictionary <JointType, Joint2D> joints2 = JointToJoint2Ds(bodyJoints);

            //List<Joint2D> jointList = joints2.Values.ToList();
            //string str = XmlUtil.Serializer(jointList);

            this.DrawBody(joints2, dc, boneDrawPen);

            // 指定 JointType.SpineMid 为坐标原点的三维空间坐标
            Dictionary <JointType, Joint> joints3 = CoordinateTransformation3D(bodyJoints, JointType.SpineMid);
            ControlCommand command = ControlCommand.GetControlCommand();

            command.SwitchLeader(body);
            command.HandClosedEvent(body);
            if (command.LeaderId == body.TrackingId)
            {
                dc.DrawEllipse(Brushes.White, new Pen(Brushes.Yellow, 2), joints2[JointType.Head].Position, 10,
                               10);
                this.DrawBoneAngle(joints3, joints2, dc, Brushes.White);
            }

            ////TODO 显示手
            //Size s = new Size(Resources.hand.Width, Resources.hand.Height);
            //Point p = new Point(joints2[JointType.WristRight].Position.X - s.Width / 2,
            //    joints2[JointType.WristRight].Position.Y - s.Height / 2);
            //Rect r = new Rect(p, s);
            //ImageSource image = Tools.BitmapToBitmapImage(Resources.hand);
            //dc.DrawImage(image, r);
        }
예제 #13
0
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }
예제 #14
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            //var beg = System.Environment.TickCount;
            base.OnRender(drawingContext);

            var scene = UIManager.Instance().GetScene();

            scene.AcquireLock();

            int nColor = m_schemeColorList.Count;

            if (nColor > 0)
            {
                var dashPattern = new List <double> {
                    5.0, 5.0 * (nColor - 1)
                };
                for (int i = 0; i < nColor; i++)
                {
                    var pen = new Pen(new SolidColorBrush(m_schemeColorList[i]), 1.5);
                    pen.DashStyle        = new DashStyle(dashPattern, 0.0);
                    pen.DashStyle.Offset = 5.0 * i;
                    pen.Thickness        = 2.0;
                    drawingContext.DrawGeometry(Brushes.Transparent, pen, m_geometry);
                }
            }

            if (m_orderData != null)
            {
                var formattedText = new FormattedText(m_orderData.m_order.ToString(),
                                                      CultureInfo.CurrentUICulture,
                                                      FlowDirection.LeftToRight,
                                                      new Typeface("tahoma"),
                                                      10.0,
                                                      Brushes.Black);
                var pos = new Point(m_orderData.m_point.X - formattedText.Width * 0.5, m_orderData.m_point.Y - formattedText.Height * 0.5);

                drawingContext.DrawEllipse(this.Stroke, new Pen(), m_orderData.m_point, 6.0, 6.0);
                drawingContext.DrawText(formattedText, pos);
            }
            scene.ReleaseLock();

            //var end = System.Environment.TickCount;
            //Logger.Debug("edge render time:" + (end-beg));
        }
예제 #15
0
        //打印一个椭圆
        private void PrintEllipseOnClick(object sender, RoutedEventArgs e)
        {
            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
                DrawingVisual  vis = new DrawingVisual();
                DrawingContext dc  = vis.RenderOpen();

                dc.DrawEllipse(Brushes.LightGray,
                               new Pen(Brushes.Black, 3),
                               new Point(dlg.PrintableAreaWidth / 2, dlg.PrintableAreaHeight / 2),
                               dlg.PrintableAreaWidth / 2,
                               dlg.PrintableAreaHeight / 2); //PrintableArea不是指页面可打印区域,而是整个页面的实际尺寸,以设备无关单位(1/96英寸)表示
                dc.Close();

                dlg.PrintVisual(vis, "My first print job");
            }
        }
예제 #16
0
            public void DrawTo(DrawingContext drawingContext)
            {
                drawingContext.DrawGeometry(SystemColors.WindowTextBrush, null, Region);
                if (Link.IsSelected)
                {
                    drawingContext.DrawEllipse(null, new Pen(SystemColors.HighlightBrush, 2), Center, Radius + 2, Radius + 2);
                }

                var tf = new Typeface(new FontFamily("Consolas"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

                Point stp = new Point(Center.X + Radius, Center.Y + Radius);

                if (Link.IsMute)
                {
                    FormattedText t = new FormattedText("M", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, tf, 12, MuteTextBrush, SoundControl.PixelsPerDip);
                    drawingContext.DrawText(t, stp);
                    stp.X += t.Width;
                }
            }
예제 #17
0
        public override void Draw(DrawingContext drawingContext, MapArea viewarea, double zoomRate)
        {
            List <PointInt> positions = collector.ToList().ConvertAll <PointInt>(
                new Converter <PointLatLng, PointInt>(ptll => { return(BingMapTileSystem.LatLngToPixelXY(ptll, MapCore.Level)); }));

            for (int i = 0; i < positions.Count; i++)
            {
                drawingContext.DrawEllipse(Brushes.Black, new Pen(),
                                           new Point((positions[i].X - viewarea.Area.X) * zoomRate, (positions[i].Y - viewarea.Area.Y) * zoomRate), radius, radius);
                if (i == 0)
                {
                    continue;
                }
                drawingContext.DrawLine(new Pen(Brushes.Blue, 2),
                                        new Point((positions[i - 1].X - viewarea.Area.X) * zoomRate, (positions[i - 1].Y - viewarea.Area.Y) * zoomRate),
                                        new Point((positions[i].X - viewarea.Area.X) * zoomRate, (positions[i].Y - viewarea.Area.Y) * zoomRate));
            }
            base.Draw(drawingContext, viewarea, zoomRate);
        }
예제 #18
0
        public void DrawHighlights(NodeHighlighter nh)
        {
            var hpen = new Pen(Brushes.White, 20);

            using (DrawingContext dc = picHighlights.RenderOpen())
            {
                foreach (var pair in nh.nodeHighlights)
                {
                    // TODO: Make more elegant? Needs profiling.
                    HighlightState hs    = pair.Value;
                    byte           red   = (byte)(hs.HasFlag(HighlightState.FromSearch) ? 255 : 0);
                    byte           green = (byte)(hs.HasFlag(HighlightState.FromAttrib) ? 255 : 0);
                    byte           blue  = (byte)(hs.HasFlag(HighlightState.FromNode) ? 255 : 0);
                    hpen = new Pen(new SolidColorBrush(Color.FromRgb(red, green, blue)), 20);

                    dc.DrawEllipse(null, hpen, pair.Key.Position, 80, 80);
                }
            }
        }
예제 #19
0
        protected override void OnRender(DrawingContext dc)
        {
            Size size = RenderSize;

            if (Stroke != null)
            {
                size.Width  = Math.Max(0, size.Width - Stroke.Thickness);
                size.Height = Math.Max(0, size.Height - Stroke.Thickness);
            }

            dc.DrawEllipse(Fill, Stroke, new Point(RenderSize.Width / 2, RenderSize.Height / 2), size.Width / 2, size.Height / 2);

            FormattedText formattedText = new FormattedText("Hello, ellipse!", CultureInfo.CurrentCulture, FlowDirection, new Typeface("Times New Roman Italic"), 24, Brushes.DarkBlue);

            Point ptText = new Point((RenderSize.Width - formattedText.Width) / 2,
                                     (RenderSize.Height - formattedText.Height) / 2);

            dc.DrawText(formattedText, ptText);
        }
예제 #20
0
        // A common way to implement an adorner's rendering behavior is to override the OnRender
        // method, which is called by the layout system as part of a rendering pass.
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (RulerParent.CurrentPosition.X > 0 && RulerParent.CurrentPosition.Y > 0 &&
                RulerParent.ShowMousePosition)
            {
                drawingContext.DrawLine(_RenderPen, new Point(RulerParent.CurrentPosition.X, 0),
                                        new Point(RulerParent.CurrentPosition.X, RulerParent.ActualHeight));

                drawingContext.DrawLine(_RenderPen, new Point(0, RulerParent.CurrentPosition.Y),
                                        new Point(RulerParent.ActualWidth, RulerParent.CurrentPosition.Y));
            }

            if (RulerParent.CurrentSnapPosition.X > 0 && RulerParent.CurrentSnapPosition.Y > 0 &&
                RulerParent.IsSnapping)
            {
                drawingContext.DrawEllipse(null, _RenderPen,
                                           new Point(RulerParent.CurrentSnapPosition.X, RulerParent.CurrentSnapPosition.Y), 10, 10);
            }
        }
예제 #21
0
        /// <summary>
        ///   Called when [render].
        /// </summary>
        /// <param name = "dc">The dc.</param>
        protected override void OnRender(DrawingContext dc)
        {
            var scaleFactor = Math.Pow(ScaleFactor, (ScaleReduction - 1));
            var brush       = defaultBrush.Clone();

            brush.Opacity = StrokeOpacity;
            var thickness = scaleFactor * defaultThickness;

            Radius = scaleFactor * defaultRadius;
            dc.DrawEllipse(Brushes.Transparent,
                           new Pen {
                Brush = defaultBrush, Thickness = thickness, DashStyle = defaultDashStyle
            },
                           Center, Radius, Radius);
            //SetValue(WidthProperty, 2 * Radius + thickness);
            //SetValue(HeightProperty, 2 * Radius + thickness);
            Panel.SetZIndex(this, int.MaxValue);
            DriftingAnimation();
        }
예제 #22
0
        public static void DrawRingSize(DrawingContext drawingContext, int ringSize, Point pos, float pixelsPerDip, Brush fillBrush, double chemistrySymbolSize)
        {
            string ringLabel  = ringSize.ToString();
            var    symbolText = new GlyphText(ringLabel,
                                              GlyphUtils.SymbolTypeface,
                                              chemistrySymbolSize,
                                              pixelsPerDip);

            Pen boundaryPen = new Pen(fillBrush, 2.0);

            symbolText.MeasureAtCenter(pos);
            var textMetricsBoundingBox = symbolText.TextMetrics.BoundingBox;

            double radius = (textMetricsBoundingBox.BottomRight - textMetricsBoundingBox.TopLeft).Length / 2 * 1.1;

            drawingContext.DrawEllipse(new SolidColorBrush(SystemColors.WindowColor), boundaryPen, pos, radius, radius);
            symbolText.Fill = fillBrush;
            symbolText.DrawAtBottomLeft(textMetricsBoundingBox.BottomLeft, drawingContext);
        }
        /// <summary>
        /// 绘制人体图像
        /// </summary>
        private void DrawBody(IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext drawingContext, Pen drawingPen)
        {
            // 骨骼绘画
            foreach (var bone in this.bones)
            {
                this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
            }

            // 对字典joints里面的每一个关节点,都操作一次
            foreach (JointType jointType in joints.Keys)
            {
                // 设置一个continue,跳过下半身的图像输出
                if (jointType == JointType.HipLeft ||
                    jointType == JointType.KneeLeft ||
                    jointType == JointType.AnkleLeft ||
                    jointType == JointType.FootLeft ||
                    jointType == JointType.HipLeft ||
                    jointType == JointType.KneeRight ||
                    jointType == JointType.AnkleRight ||
                    jointType == JointType.FootRight)
                {
                    continue;
                }

                Brush drawBrush = null;

                TrackingState trackingState = joints[jointType].TrackingState;

                if (trackingState == TrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (trackingState == TrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
                }
            }
        }
예제 #24
0
        protected override void OnRender(DrawingContext context)
        {
            base.OnRender(context);

            double width  = ActualWidth * 0.9;
            double height = ActualHeight * 0.9;

            Point start = new Point(width * .1, height * .1);
            Point end   = new Point(width, height);


            //you need a pen to draw
            Pen pen = new Pen(Brushes.Brown, 3.5);

            //draw a filled retangle
            context.DrawRectangle(Brushes.LightCyan, pen, new Rect(start, end));

            start = new Point(width * .3, height * .4);
            end   = new Point(width * .95, height * .95);
            pen   = new Pen(Brushes.DarkGreen, 5);

            //draw a rectanglular outline
            context.DrawRectangle(null, pen, new Rect(start, end));

            Point center = new Point(width / 2, height / 2);

            pen = new Pen(Brushes.Yellow, 5);

            //draw a circle
            context.DrawEllipse(null, pen, center, 200, 200);



            //create a radial brush
            Brush _brush = new RadialGradientBrush(Color.FromRgb(255, 0, 0), Color.FromRgb(0, 0, 255));

            start = new Point(width * .1, height * .2);
            end   = new Point(width * .95, height * .2);

            //draw a line
            pen = new Pen(_brush, 10);
            context.DrawLine(pen, start, end);
        }
예제 #25
0
        // Точка
        public void Draw(Point point, string text)
        {
            DrawingContext myVisualContext = myVisual.RenderOpen();

            Pen ellipsePen = new Pen(Brushes.MediumTurquoise, 3);

            myVisualContext.DrawEllipse(ellipsePen.Brush, ellipsePen, point, 5, 5);

            string formattedTextPoint = ProcessingData.FromPointToString(point);

            FormattedText formattedText = new FormattedText(formattedTextPoint + "\n" + text, new CultureInfo("ru-RU"), FlowDirection.LeftToRight,
                                                            new Typeface("Verdana"), 10, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip);

            Point formattedPoint = new Point(point.X, point.Y + 10);

            myVisualContext.DrawText(formattedText, formattedPoint);

            myVisualContext.Close();
        }
예제 #26
0
        // Draw the inner border
        private void DrawHighlight(DrawingContext dc, ref Rect bounds)
        {
            Pen highlightPen = HighlightPen;

            if (highlightPen != null && (bounds.Width >= 4.0) && (bounds.Height >= 4.0))
            {
                if (!IsRound)
                {
                    dc.DrawRectangle(null, highlightPen, new Rect(bounds.Left + 1.0, bounds.Top + 1.0, bounds.Width - 2.0, bounds.Height - 2.0));
                }
                else 
                {
                    double centerX = bounds.Width * 0.5;
                    double centerY = bounds.Height * 0.5;

                    dc.DrawEllipse(null, highlightPen, new Point(centerX, centerY), centerX - 2, centerY - 2);
                }
            }
        }
예제 #27
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     for (int y = 0; y < (int)ActualHeight / 4; y++)
     {
         for (int x = 0; x < (int)ActualWidth / 4; x++)
         {
             if (IsCircle)
             {
                 drawingContext.DrawEllipse(Foreground, null,
                                            new Point(x * 4 + 2, y * 4 + 2), 1, 1);
             }
             else
             {
                 drawingContext.DrawRectangle(Foreground, null,
                                              new Rect(x * 4, y * 4, 2, 2));
             }
         }
     }
 }
 public void DrawAtFieldImageInCube(DrawingContext drawingContext, double x, double y, ImageSource imageToDraw)
 {
     if (cubeLineSize_Optimized < minLineSize)
     {
         drawingContext.DrawEllipse(imageBrush, null,
                                    new Point(x + halfCubeLineSize, y + halfCubeLineSize),
                                    halfCubeLineSize_Optimized, halfCubeLineSize_Optimized
                                    );
     }
     else
     {
         drawingContext.DrawImage(
             imageToDraw,
             new Rect(
                 new Point(x + cubeLineSize_Optimized_PercentForIndent, y + cubeLineSize_Optimized_PercentForIndent), cubeSize_Optimized
                 )
             );
     }
 }
예제 #29
0
        // 渲染原型.
        private void DrawEllipse(DrawingVisual visual, string sName, Point center)
        {
            using (DrawingContext dc = visual.RenderOpen())
            {
                Brush brush = drawingBrush;

                dc.DrawEllipse(brush, drawingPen, center, radius, radius);
                FormattedText text = new FormattedText(sName,
                                                       System.Globalization.CultureInfo.CurrentCulture,
                                                       System.Windows.FlowDirection.LeftToRight,
                                                       new Typeface("Times New Roman"),
                                                       12,
                                                       TextBrush
                                                       );
                int Height = Convert.ToInt32(text.Height);
                int Width  = Convert.ToInt32(text.Width);
                dc.DrawText(text, new Point(center.X - Width / 2, center.Y - Height / 2));
            }
        }
예제 #30
0
        private void DrawGrid(DrawingContext dc)
        {
            Pen p = new Pen(Brushes.Green, 1);

            dc.DrawEllipse(Brushes.Blue, p, new Point(320, 240), 5, 5);
            dc.DrawLine(p, new Point(80, 0), new Point(560, 480));
            dc.DrawLine(p, new Point(80, 480), new Point(560, 0));
            int cellSize = 20;

            for (int y = 0; y < 480; y += cellSize)
            {
                dc.DrawLine(p, new Point(0, y), new Point(640, y));
            }

            for (int x = 0; x < 640; x += cellSize)
            {
                dc.DrawLine(p, new Point(x, 0), new Point(x, 480));
            }
        }
예제 #31
0
 // Draws joint as circle
 private void DrawJoints(DrawingContext dc, Skeleton skeleton)
 {
     foreach (var jointType in JointTypes.All)
     {
         var joint   = skeleton[jointType];
         var point2D = ProjectJointToImage(joint);
         if (point2D.HasValue)
         {
             var radius = JointCircleRadius;
             // smaller radius for face features (eyes, ears, nose)
             if (jointType.IsFaceFeature())
             {
                 radius /= 2;
             }
             var fillBrush = JointConfidenceLevelToToBrush(joint.ConfidenceLevel);
             dc.DrawEllipse(fillBrush, JointBorder, point2D.Value, radius, radius);
         }
     }
 }