コード例 #1
3
ファイル: TestControl.cs プロジェクト: pascalfr/MPfm
        public void CreateBitmap()
        {
            int width = 100;
            int height = 100;
            int dpi = 96;

            Tracing.Log(">> CreateBitmap");
            var thread = new Thread(new ThreadStart(() => 
            {
                Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual");
                //Dispatcher.Invoke(new Action(() => {
                _drawingVisual = new DrawingVisual();
                _drawingContext = _drawingVisual.RenderOpen();
                //}));

                Tracing.Log(">> CreateBitmap - Drawing to context");
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50));
                _drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50));
                _drawingContext.Close();

                Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap");
                _bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default);
                _bitmap.Render(_drawingVisual);
                Tracing.Log(">> CreateBitmap - Finished work");
                _bitmap.Freeze();
            }));
            //thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
コード例 #2
0
        public static Sm.DrawingVisual ToVisualDrawing(this Shape input)
        {
            Sm.DrawingVisual  drawingVisual  = new Sm.DrawingVisual();
            Sm.DrawingContext drawingContext = drawingVisual.RenderOpen();
            Sm.GeometryGroup  drawing        = new Sm.GeometryGroup();

            if (input.IsCompound)
            {
                foreach (Geometry geo in input.Geometries)
                {
                    Sm.Geometry geometry = geo.ToGeometry();
                    drawing.Children.Add(geometry);
                }
            }
            else
            {
                Sm.Geometry geometry = input.ToGeometry();
                drawing.Children.Add(geometry);
            }

            drawingContext.DrawGeometry(input.Graphic.Fill.ToMediaBrush(), input.Graphic.Stroke.ToMediaPen(), drawing);
            drawingContext.Close();

            if (input.Graphic.Effects.HasBlurEffect)
            {
                drawingVisual.Effect = input.Graphic.Effects.Blur.ToMediaEffect();
            }
            if (input.Graphic.Effects.HasShadowEffect)
            {
                drawingVisual.Effect = input.Graphic.Effects.Shadow.ToMediaEffect();
            }

            return(drawingVisual);
        }
コード例 #3
0
        public DrawingVisual RenderDiagram(SequenceDiagram sequenceDiagram)
        {
            _nodeMiddlePoints = new Dictionary<Guid, double>();
            _diagramSize = new Size(0.5, 80.5);

            var canvas = new DrawingVisual();
            _context = canvas.RenderOpen();

            DrawAllNodes(sequenceDiagram);
            DrawAllDiagramElements(sequenceDiagram);
            DrawVerticalLines(sequenceDiagram);

            _context.Close();
            return canvas;
        }
コード例 #4
0
        private void DrawingGeometry(DrawingContext drawingContext, double value, double maxValue, double radiusX, double radiusY, double thickness, double padding)
        {
            if (Math.Abs(value - maxValue) > 0.00001)
            {
                var brush = value < WarnValue ? WarnBrush : NormalBrush;
                drawingContext.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromRgb(0xdd, 0xdf, 0xe1)), thickness), _centerPoint, radiusX, radiusY);
                drawingContext.DrawGeometry(brush, new Pen(), GetGeometry(value, maxValue, radiusX, thickness, padding));
                var formatWords = new FormattedText(_percentString,
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    SuccessRateTypeface,
                    SuccessRateFontSize,
                    brush);
                var startPoint = new Point(_centerPoint.X - formatWords.Width / 2, _centerPoint.Y - formatWords.Height / 2);
                drawingContext.DrawText(formatWords, startPoint);
            }
            else
            {
                drawingContext.DrawEllipse(null, new Pen(NormalBrush, thickness), _centerPoint, radiusX, radiusY);
                var formatWords = new FormattedText("100%",
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    SuccessRateTypeface,
                    SuccessRateFontSize,
                    NormalBrush);
                var startPoint = new Point(_centerPoint.X - formatWords.Width / 2, _centerPoint.Y - formatWords.Height / 2);
                drawingContext.DrawText(formatWords, startPoint);
            }

            drawingContext.Close();
        }
コード例 #5
0
        private void DrawingGeometry(DrawingContext drawingContext, double value, double maxValue, double radiusX, double radiusY, double thickness, double padding)
        {
            if (value != maxValue) {
                SolidColorBrush brush;
                if (value < WarnValue) {
                    brush = WarnBrush;
                } else {
                    brush = NormalBrush;
                }
                drawingContext.DrawEllipse(null, new Pen(WarnBrush, thickness), centerPoint, radiusX, radiusY);
                //drawingContext.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromRgb(0xdd, 0xdf, 0xe1)), thickness), centerPoint, radiusX, radiusY);
                drawingContext.DrawGeometry(NormalBrush, new Pen(), GetGeometry(value, maxValue, radiusX, radiusY, thickness, 0));
                FormattedText formatWords = new FormattedText(percentString,
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    SuccessRateTypeface,
                    SuccessRateFontSize,
                    TextBrush);
                Point startPoint = new Point(centerPoint.X - formatWords.Width / 2, centerPoint.Y - formatWords.Height / 2);
                drawingContext.DrawText(formatWords, startPoint);
            } else {
                drawingContext.DrawEllipse(null, new Pen(NormalBrush, thickness), centerPoint, radiusX, radiusY);
                FormattedText formatWords = new FormattedText("0 s",
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    SuccessRateTypeface,
                    SuccessRateFontSize,
                    TextBrush);
                Point startPoint = new Point(centerPoint.X - formatWords.Width / 2, centerPoint.Y - formatWords.Height / 2);
                drawingContext.DrawText(formatWords, startPoint);
            }

            drawingContext.Close();
        }
コード例 #6
0
ファイル: VisualNode.cs プロジェクト: samuto/designscript
        protected virtual void ComposeCore(DrawingContext drawingContext, DrawingVisual visual)
        {
            if (this.Visible == false)
            {
                drawingContext.Close();
                return;
            }

            //draw rounded rectangle
            RectangleGeometry roundedRect = new RectangleGeometry();
            int tempWidth = (int)Width;
            int tempHeight = (int)Height;
            //@TODO(Ben) please double check this is recomended behaviour and insert guidance url here
            roundedRect.Rect = new Rect(new Point(0.5, 0.5), new Point(tempWidth + 0.5, tempHeight + 0.5));
            //roundedRect.RadiusX = Configurations.CornerRadius;
            //roundedRect.RadiusY = Configurations.CornerRadius;

            //@TODO(Ben) extract this into a common place, don't recreate.
            //@TODO(Ben) Move this numbers to constant fields in configurations
            DropShadowEffect shadowEffect = new DropShadowEffect();
            shadowEffect.BlurRadius = Configurations.BlurRadius;
            shadowEffect.Color = Configurations.SelectionColor;
            shadowEffect.Direction = Configurations.Direction;
            shadowEffect.ShadowDepth = Configurations.ShadowDepth;
            shadowEffect.Opacity = Configurations.Opacity;

            drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.BorderPen, roundedRect);

            //@TODO(Ben) If previewSelected != true remove the effect, don't just make it white
            if (this.PreviewSelected == true)
            {
                drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.SelectionBorderPen, roundedRect);
                visual.Effect = shadowEffect;
            }
            else
            {
                drawingContext.DrawGeometry(Configurations.RectWhite, Configurations.BorderPen, roundedRect);
                shadowEffect.Opacity = 0;
                shadowEffect.Color = Configurations.SelectionColorWhite;
                visual.Effect = shadowEffect;
            }

            if (partDisplayingMenu == NodePart.NorthEast)
            {
                //@TODO(Joy) Magic numbers, lalalala, magic numbers
                //@TODO: XAMLify this
                Rect newRect = new Rect(new Point(Width - 30, -20), new Size(50, 50));
            }
            else if (partDisplayingMenu == NodePart.PreviewNorthEast)
            {
                Point pt = this.previewBubble.RectPosition;
                pt.Offset(this.previewBubble.Width - 30, -20);

                Rect newRect = new Rect(pt, new Size(50, 50));
            }
        }
コード例 #7
0
ファイル: MovingText.cs プロジェクト: BI-LedTable/LedTable
        public void MovingText_execute()
        {
            switch (mode)
            {
                case "Links nach Rechts":
                    counter++;
                   textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
                    if (Pos.X > -text.Width)
                        Pos.X--;
                    else Pos.X = 68;
                    break;
                case "Rechts nach Links":
                    {
                        counter++;
                        textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
                        if (Pos.X < 68)
                            Pos.X++;
                        else Pos.X = -text.Width;
                        break;
                    }

                case "Oben/Unten":
                    counter++;
                   textBox.Foreground = new SolidColorBrush(colors[counter % 360]);
                    if (Pos.Y < 42)
                        Pos.Y++;
                    else Pos.Y= -text.Height;
                    break;
            }

            renderTargetBitmap.Clear();
            using( monitor.GetBitmapContext())
            {

                //string time = DateTime.Now.Hour + " : " + DateTime.Now.Minute + " : " + DateTime.Now.Second;

                text = new FormattedText(textBox.Text,
                new CultureInfo("de-de"),
                FlowDirection.LeftToRight,
                new Typeface(textBox.FontFamily, FontStyles.Normal, textBox.FontWeight, new FontStretch()),
                textBox.FontSize,
                textBox.Foreground);

                text.LineHeight = textBox.FontSize;
                drawingContext = drawingVisual.RenderOpen();
                drawingContext.DrawText(text, Pos);
                drawingContext.Close();

                renderTargetBitmap.Render(drawingVisual);
                renderTargetBitmap.CopyPixels(new Int32Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight),
                                            monitor.BackBuffer, monitor.BackBufferStride * monitor.PixelHeight, monitor.BackBufferStride);

            }
        }
コード例 #8
0
        private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            float headloc = 0;

            float LefthandlocY = 0;
            float LefthandlocX = 0;

            float RighthandlocY = 0;
            float RighthandlocX = 0;

            int movementcount = 0;

            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

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

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }

                //find head location

                if (joint.JointType == JointType.Head)
                {
                    headloc = joint.Position.Y;
                }

                //find left hand location
                if (joint.JointType == JointType.HandLeft)
                {
                    LefthandlocY = joint.Position.Y;
                    LefthandlocX = joint.Position.X;
                }

                //find right hand location
                if (joint.JointType == JointType.HandRight)
                {
                    RighthandlocY = joint.Position.Y;
                    RighthandlocX = joint.Position.X;
                }

            }
            //see if left hand is above head

            if (LefthandlocY > headloc && movementcount == 0)
            {

                Indicator.Background = new SolidColorBrush(Colors.Green);

                SendKeys.SendWait("{LEFT}");

                movementcount = movementcount + 1;

            }

            // see if right hand is above head

            if (RighthandlocY > headloc && movementcount == 0)
            {
                SendKeys.SendWait("{RIGHT}");

                movementcount = movementcount + 1;
            }

            // see if hands are crossed

            if (LefthandlocX > RighthandlocX && movementcount == 0)
            {
                SendKeys.SendWait("z");
                CrossIndicator.Background = new SolidColorBrush(Colors.Purple);
                movementcount = movementcount + 1;

            }

            drawingContext.Close();
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: kittttttan/test
 /// <summary>
 /// Unlimited redo
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MenuItem_Redo_Click(object sender, RoutedEventArgs e)
 {
     int count = bitmapHistory.Count;
     if (count > 0) {
         bitmap.Clear();
         drawContext = drawVisual.RenderOpen();
         drawContext.DrawImage(bitmapHistory.Pop(),
             new Rect(0, 0, imageWidth, imageHeight));
         drawContext.Close();
         bitmap.Render(drawVisual);
     }
 }
コード例 #10
0
ファイル: MainWindow.xaml.cs プロジェクト: kittttttan/test
        private void MenuItem_Open_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();
            dlg.Filter = "PNG(*.png)|*.png";
            if (dlg.ShowDialog() == true) {
                using (FileStream stream = new FileStream(dlg.FileName,
                        FileMode.Open, FileAccess.Read)) {
                    try {
                        BitmapImage src = new BitmapImage();
                        src.BeginInit();
                        src.StreamSource = stream;
                        src.CacheOption = BitmapCacheOption.OnLoad;
                        src.EndInit();
                        //image1.Source = src;

                        bitmapHistory.Push((RenderTargetBitmap)bitmap.Clone());
                        bitmap.Clear();
                        drawContext = drawVisual.RenderOpen();
                        drawContext.DrawImage(src,
                            new Rect(0, 0, imageWidth, imageHeight));
                        drawContext.Close();
                        bitmap.Render(drawVisual);

                    } catch (Exception ex) {
                        MessageBox.Show(ex.ToString(), "Exception",
                            MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
コード例 #11
0
ファイル: MainWindow.xaml.cs プロジェクト: kittttttan/test
 /// <summary>
 /// Preview drawing
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void image_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed) {
         Point pt = e.GetPosition(image1);
         Point rpt = ConvertPoint(pt);
         previewBitmap.Clear();
         drawContext = drawVisual.RenderOpen();
         Pen penDraw = new Pen(brush, penThick);
         switch (drawType) {
         case DrawType.Line:
             drawContext.DrawLine(penDraw, ptLast, rpt);
             break;
         case DrawType.Box:
             drawContext.DrawRectangle(fillBrush, penDraw, new Rect(ptLast, rpt));
             break;
         case DrawType.Circle: {
                 double r = CalcDist(ptLast, rpt);
                 drawContext.DrawEllipse(fillBrush, penDraw, ptLast, r, r);
             }
             break;
         default:
             break;
         }
         drawContext.Close();
         previewBitmap.Render(drawVisual);
     }
 }