public void DrawFaceRectangle(Image image, BitmapImage bitmapSource, Emotion[] emotionResult)
        {
            if (emotionResult != null && emotionResult.Length > 0)
            {
                DrawingVisual  visual         = new DrawingVisual();
                DrawingContext drawingContext = visual.RenderOpen();

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

                double dpi          = bitmapSource.DpiX;
                double resizeFactor = 96 / dpi;

                foreach (var emotion in emotionResult)
                {
                    Microsoft.ProjectOxford.Common.Rectangle faceRect = emotion.FaceRectangle;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(Brushes.Cyan, 4),
                        new Rect(
                            faceRect.Left * resizeFactor,
                            faceRect.Top * resizeFactor,
                            faceRect.Width * resizeFactor,
                            faceRect.Height * resizeFactor)
                        );
                }

                drawingContext.Close();

                RenderTargetBitmap faceWithRectBitmap = new RenderTargetBitmap(
                    (int)(bitmapSource.PixelWidth * resizeFactor),
                    (int)(bitmapSource.PixelHeight * resizeFactor),
                    96,
                    96,
                    PixelFormats.Pbgra32);

                faceWithRectBitmap.Render(visual);

                image.Source = faceWithRectBitmap;
            }
        }
Ejemplo n.º 2
0
        internal void Compose()
        {
            if (false == this.Dirty)
            {
                return;
            }

            if (IsRunningHeadless)
            {
                return;
            }

            GraphController  controller = graphController as GraphController;
            IGraphVisualHost visualHost = controller.GetVisualHost();

            DrawingVisual visual = visualHost.GetDrawingVisualForNode(this.NodeId);
            //TextOptions.SetTextFormattingMode(visual, TextFormattingMode.Display);
            //TextOptions.SetTextRenderingMode(visual, TextRenderingMode.Aliased);
            DrawingContext drawingContext = visual.RenderOpen();
            CultureInfo    cultureInfo    = new CultureInfo("en-us"); //@TODO(Ben) Move this into a single place and reuse it

            //RenderOptions.SetEdgeMode(visual, EdgeMode.Aliased);
            if (!dotsFlag.HasFlag(MenuDots.DotsFlag))
            {
                this.CheckDots();
            }

            this.ComposeCore(drawingContext, visual);
            drawingContext.Close();

            if (errorBubble != null)
            {
                errorBubble.Compose();
            }

            TranslateTransform nodeTransform = visual.Transform as TranslateTransform;

            nodeTransform.X = this.nodePosition.X;
            nodeTransform.Y = this.nodePosition.Y;

            this.Dirty = false;
        }
Ejemplo n.º 3
0
        public void drawCurrent(int[,] gen)
        {
            diameter = Convert.ToDouble(txt_diameter.Text);
            double pixelW = 4, pixelH = 4;



            DrawingVisual  vis = new DrawingVisual();
            DrawingContext dc  = vis.RenderOpen();


            for (int i = 0; i < h + 2; i++)
            {
                pixelW = 4;
                for (int j = 0; j < w + 2; j++)
                {
                    if (gen[i, j] == 2)
                    {
                        dc.DrawEllipse(brushColor[0], blkPen, new System.Windows.Point(pixelW, pixelH), diameter / 2, diameter / 2);
                    }
                    else if (gen[i, j] == 1)
                    {
                        dc.DrawEllipse(brushColor[1], blkPen, new System.Windows.Point(pixelW, pixelH), diameter / 2, diameter / 2);
                    }
                    if (i == (h + 2) / 2 && j == (w - 1) / 2 + 1 && gen[i, j] == 1)
                    {
                        dc.DrawEllipse(brushColor[2], blkPen, new System.Windows.Point(pixelW, pixelH), diameter / 2, diameter / 2);
                    }
                    if (gen[i, j] == 1 && j == 1 + (w - 1) / 2 && i == (h + 2) / 2 - 1)
                    {
                        dc.DrawEllipse(brushColor[2], blkPen, new System.Windows.Point(pixelW, pixelH), diameter / 2, diameter / 2);
                    }
                    pixelW += diameter;
                }
                pixelH += diameter;
            }
            dc.Close();
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)(400 * ((double)num_sand / 400)), (int)(400 * ((double)num_sand / 400)), 96, 96, PixelFormats.Pbgra32);

            bmp.Render(vis);
            img.Source = bmp;
        }
Ejemplo n.º 4
0
        public override void Render()
        {
            //first work out the angle bracket size
            double bondLength    = ParentMolecule.Model.XamlBondLength;
            double bracketLength = Globals.BracketFactor * bondLength;
            //now work out the main area
            Brush mainArea = new SolidColorBrush(Colors.Gray);

            mainArea.Opacity = MainAreaOpacity;
            Brush bracketBrush = ShowInColour ? new SolidColorBrush(Globals.GroupBracketColor) : new SolidColorBrush(Colors.Black);
            Pen   bracketPen   = new Pen(bracketBrush, Globals.BracketThickness);

            bracketPen.StartLineCap = PenLineCap.Round;
            bracketPen.EndLineCap   = PenLineCap.Round;

            using (DrawingContext dc = RenderOpen())
            {
                var inflateFactor = ParentMolecule.Model.XamlBondLength * Globals.GroupInflateFactor;
                var bb            = BoundingBox;

                bb.Inflate(new Size(inflateFactor, inflateFactor));

                dc.DrawRectangle(mainArea, null, bb);
                Vector right = new Vector(bracketLength, 0);
                Vector left  = -right;
                Vector down  = new Vector(0, bracketLength);
                Vector up    = -down;

                dc.DrawLine(bracketPen, bb.BottomLeft, bb.BottomLeft + right);
                dc.DrawLine(bracketPen, bb.BottomLeft, bb.BottomLeft + up);

                dc.DrawLine(bracketPen, bb.BottomRight, bb.BottomRight + left);
                dc.DrawLine(bracketPen, bb.BottomRight, bb.BottomRight + up);

                dc.DrawLine(bracketPen, bb.TopLeft, bb.TopLeft + right);
                dc.DrawLine(bracketPen, bb.TopLeft, bb.TopLeft + down);

                dc.DrawLine(bracketPen, bb.TopRight, bb.TopRight + left);
                dc.DrawLine(bracketPen, bb.TopRight, bb.TopRight + down);
                dc.Close();
            }
        }
Ejemplo n.º 5
0
    public RenderTargetBitmap RenderBitmap(FrameworkElement element)
    {
        double         topLeft      = 0;
        double         topRight     = 0;
        int            width        = (int)element.ActualWidth;
        int            height       = (int)element.ActualHeight;
        double         dpiX         = 96; // this is the magic number
        double         dpiY         = 96; // this is the magic number
        PixelFormat    pixelFormat  = PixelFormats.Default;
        VisualBrush    elementBrush = new VisualBrush(element);
        DrawingVisual  visual       = new DrawingVisual();
        DrawingContext dc           = visual.RenderOpen();

        dc.DrawRectangle(elementBrush, null, new Rect(topLeft, topRight, width, height));
        dc.Close();
        RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, dpiX, dpiY, pixelFormat);

        bitmap.Render(visual);
        return(bitmap);
    }
Ejemplo n.º 6
0
        // Constructor requires Color argument.
        public ColorCell(Color clr)
        {
            // Create a new DrawingVisual and store as field.
            visColor = new DrawingVisual();
            DrawingContext dc = visColor.RenderOpen();

            // Draw a rectangle with the color argument.
            Rect rect = new Rect(new Point(0, 0), sizeCell);

            rect.Inflate(-4, -4);
            Pen pen = new Pen(SystemColors.ControlTextBrush, 1);

            brush = new SolidColorBrush(clr);
            dc.DrawRectangle(brush, pen, rect);
            dc.Close();

            // AddVisualChild is necessary for event routing!
            AddVisualChild(visColor);
            AddLogicalChild(visColor);
        }
Ejemplo n.º 7
0
        private Rectangle CreateIcon(Point origin, out Visual visual)
        {
            if (_category != null)
            {
                ImageSource src = NodeCategories.GetIcon(_category);
                if (src != null)
                {
                    DrawingVisual icon = new DrawingVisual();
                    icon.CacheMode = new BitmapCache(1);
                    DrawingContext context = icon.RenderOpen();
                    context.DrawImage(src, new Rect(origin.X, origin.Y, _fontSize, _fontSize));
                    context.Close();

                    visual = icon;
                    return(new Rectangle(origin.X, origin.Y, _fontSize, _fontSize));
                }
            }
            visual = null;
            return(new Rectangle());
        }
Ejemplo n.º 8
0
        private void createDrawing()
        {
            FormattedText formattedText
                = new FormattedText(
                      text,
                      CultureInfo.CurrentUICulture,
                      FlowDirection.LeftToRight,
                      CreateTypeFace(),
                      GetFontSize(),
                      GetForeGround(),
                      null,
                      VisualTreeHelper.GetDpi(drawingVisual)
                      .PixelsPerDip);

            lineHeight = formattedText.LineHeight;
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawText(formattedText, new Point());
            drawingContext.Close();
        }
Ejemplo n.º 9
0
        // 旗帜
        public void CreateDrawingVisualFlag(Brush gBrush, Pen gPen, Point startPoint, Size flagSize)
        {
            //旗 M0,20 C50,-20 100,40 150,0 L150,100 C100,120 50,80 0,120
            PathGeometry flaggeo = new PathGeometry();
            PathFigure   ffg     = new PathFigure();

            ffg.StartPoint = new Point(startPoint.X, startPoint.Y + 20);
            ffg.Segments.Add(new BezierSegment(new Point(startPoint.X + flagSize.Width / 3, startPoint.Y - 20), new Point(startPoint.X + flagSize.Width * 2 / 3, startPoint.Y + 20), new Point(startPoint.X + flagSize.Width, startPoint.Y), true));
            ffg.Segments.Add(new LineSegment(new Point(startPoint.X + flagSize.Width, startPoint.Y + flagSize.Height), true));
            ffg.Segments.Add(new BezierSegment(new Point(startPoint.X + flagSize.Width * 2 / 3, startPoint.Y + flagSize.Height + 20), new Point(startPoint.X + flagSize.Width / 3, startPoint.Y + flagSize.Height - 20), new Point(startPoint.X, startPoint.Y + flagSize.Height + 20), true));
            flaggeo.Figures.Add(ffg);
            flaggeo.Freeze();

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

            drawingContext.DrawGeometry(gBrush, gPen, flaggeo);
            drawingContext.Close();
            _children.Add(drawingVisual);
        }
Ejemplo n.º 10
0
 public void Highlight(List <ClassObject> list)
 {
     HighlightedObjects.ForEach(v => children.Remove(v));
     HighlightedObjects.Clear();
     if (list != null)
     {
         list.ForEach(o =>
         {
             DrawingVisual visual   = new DrawingVisual();
             DrawingContext context = visual.RenderOpen();
             Color fill             = FromClass(o.C);
             fill.A = 200;
             context.DrawRectangle(new SolidColorBrush(FromClass(o.C)), new Pen(new SolidColorBrush(fill), 3),
                                   new Rect(o.X - 3, o.Y - 3, 6, 6));
             context.Close();
             this.children.Add(visual);
             this.HighlightedObjects.Add(visual);
         });
     }
 }
Ejemplo n.º 11
0
        //Return view as RenderTargetBitmap
        public static RenderTargetBitmap GetImage(Canvas view)
        {
            Size size = new Size(view.ActualWidth, view.ActualHeight);

            if (size.IsEmpty)
            {
                return(null);
            }
            RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);

            DrawingVisual drawingvisual = new DrawingVisual();

            using (DrawingContext context = drawingvisual.RenderOpen())
            {
                context.DrawRectangle(new VisualBrush(view), null, new Rect(new Point(), size));
                context.Close();
            }
            result.Render(drawingvisual);
            return(result);
        }
Ejemplo n.º 12
0
        // Token: 0x0600350B RID: 13579 RVA: 0x000F02E0 File Offset: 0x000EE4E0
        private Visual GetVisual(double offsetX, double offsetY)
        {
            ContainerVisual containerVisual = new ContainerVisual();
            DrawingVisual   drawingVisual   = new DrawingVisual();

            containerVisual.Children.Add(drawingVisual);
            drawingVisual.Offset = new Vector(offsetX, offsetY);
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawDrawing(this._page.GetDrawing());
            drawingContext.Close();
            UIElementCollection children = this._page.Children;

            foreach (object obj in children)
            {
                UIElement old = (UIElement)obj;
                this.CloneVisualTree(drawingVisual, old);
            }
            return(containerVisual);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 현재 객체의 그래픽 요소를 비트맵으로 변환합니다.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static RenderTargetBitmap ConverterBitmapImage(FrameworkElement element)
        {
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            // 해당 객체의 그래픽요소로 사각형의 그림을 그립니다.
            drawingContext.DrawRectangle(new VisualBrush(element), null,
                                         //new Rect(new Point(0, 0), new Point(element.ActualWidth, element.ActualHeight)));
                                         new Rect(new Point(0, 0), new Point(500, 500)));
            drawingContext.Close();

            // 비트맵으로 변환합니다.
            RenderTargetBitmap target =
                //new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight,
                new RenderTargetBitmap(500, 500,
                                       96, 96, System.Windows.Media.PixelFormats.Pbgra32);

            target.Render(drawingVisual);
            return(target);
        }
        private void DrawSkeletonOnVideo(CoordinateMapper coordinateMapper, Skeleton skeleton)
        {
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            foreach (Microsoft.Kinect.Joint joint in skeleton.Joints)
            {
                ColorImagePoint colorImagePoint = coordinateMapper.MapSkeletonPointToColorPoint(
                    joint.Position, ColorImageFormat.RgbResolution640x480Fps30);

                Point point = new Point(colorImagePoint.X, colorImagePoint.Y);
                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), new Pen(new SolidColorBrush(Colors.White), 3), point, 7, 7);
            }

            drawingContext.Close();
            RenderTargetBitmap renderBmp = new RenderTargetBitmap(640, 480, 96d, 96d, PixelFormats.Pbgra32);

            renderBmp.Render(drawingVisual);
            skeletonFrame.Source = renderBmp;
        }
Ejemplo n.º 15
0
        private DrawingVisual DrawTarget()
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            // Retrieve the DrawingContext in order to create new drawing content.
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            var height = (Parent as FrameworkElement).ActualHeight;
            var width = (Parent as FrameworkElement).ActualWidth;

            var pen = new Pen(Application.Current.Resources["ConstellationTargetBrush"] as Brush, 2);
            pen.Freeze();

            drawingContext.DrawLine(pen, new Point(0, height / 2), new Point(width, height / 2));
            drawingContext.DrawLine(pen, new Point(width / 2, 0), new Point(width / 2, height));

            drawingContext.Close();

            return drawingVisual;
        }
Ejemplo n.º 16
0
        public static Icon CreateTaskbarIcon(string text)
        {
            DrawingVisual dv = new();

            using DrawingContext dc = dv.RenderOpen();
            FormattedText temperatureFormattedText = new(
                (text != null) ? text + "°" : "??",
                new System.Globalization.CultureInfo("en-us"),
                FlowDirection.LeftToRight,
                GetRobotoRegularTypeface(),
                11,
                System.Windows.Media.Brushes.White,
                null,
                TextFormattingMode.Ideal,
                4.0);

            dc.DrawText(temperatureFormattedText, new System.Windows.Point(0, 0));
            dc.Close();
            return(CreateIcon(16, 16, dv));
        }
Ejemplo n.º 17
0
        private void buttonUndo_Click(object sender, RoutedEventArgs e)
        {
            ptinfos.Clear();             // REM 清除一笔中所有点
            CreateNewBitmap();

            if ((geos.Count > 0))
            {
                strokes.RemoveAt(strokes.Count - 1);           // REM 清除上一笔

                geos.RemoveAt(geos.Count - 1);                 // REM 清除上一笔
                DrawingContext dc = dv.RenderOpen();
                foreach (var g in geos)
                {
                    GeometryDrawing drawing = new GeometryDrawing(Brushes.Black, new Pen(Brushes.Black, 1), g);
                    dc.DrawDrawing(drawing);
                }
                dc.Close();
                bmp.Render(dv);
            }
        }
Ejemplo n.º 18
0
        public static RenderTargetBitmap GetImage(UserControl view)
        {
            int  qualityFactor = 10;
            int  dotsPerInch   = 96;
            Size size          = new Size((int)view.ActualWidth * qualityFactor, (int)view.ActualHeight * qualityFactor);

            if (size.IsEmpty)
            {
                return(null);
            }

            RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width, (int)size.Height, dotsPerInch,
                                                               dotsPerInch, PixelFormats.Pbgra32);
            DrawingVisual drawingvisual = new DrawingVisual();

            using (DrawingContext context = drawingvisual.RenderOpen()) {
                context.DrawRectangle(new VisualBrush(view), null, new Rect(new Point(), size));
                context.Close();
            }
        }
Ejemplo n.º 19
0
        private static Tuple <DrawingVisual, SolidColorBrush> CreateEllipse(double size)
        {
            DrawingVisual retVal = new DrawingVisual();

            DrawingContext context = retVal.RenderOpen();

            double half = size / 2d;

            SolidColorBrush brush = new SolidColorBrush(UtilityWPF.ColorFromHex("80FFFFFF"));

            context.DrawEllipse(
                brush,
                new Pen(new SolidColorBrush(UtilityWPF.ColorFromHex("80000000")), 1),
                new Point(0, 0), half, half);

            // Persist the drawing content.
            context.Close();

            return(Tuple.Create(retVal, brush));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Generates the underlying renderable visual. This method must be called before assigning this node to a parent element.
        /// </summary>
        /// <param name="verticalLength">The desired length of the line below this node.</param>
        public void GenerateVisual(double verticalLength)
        {
            // Start drawing
            DrawingVisual  drawing        = new DrawingVisual();
            DrawingContext drawingContext = drawing.RenderOpen();

            // Draw header

            /*drawingContext.DrawRectangle(Brushes.White, new Pen(Brushes.Black, 2), new Rect(0, 0, Width, 20));
             * drawingContext.DrawText(_formattedFunctionName, new Point(5, 5));*/

            // Draw vertical line
            drawingContext.DrawRectangle(Brushes.DarkGray, new Pen(Brushes.DarkGray, 2), new Rect(Width / 2 - 2, 20, 4, verticalLength));

            // Finish drawing
            drawingContext.Close();

            // Save drawing
            _visual = drawing;
        }
Ejemplo n.º 21
0
        // 倒三角形
        public void CreateDrawingTriangle2(Brush rBrush, Pen rPen, Point rCenter, double rWidth, double rHeight)
        {
            PathGeometry flaggeo = new PathGeometry();
            PathFigure   ffg     = new PathFigure {
                StartPoint = new Point(rCenter.X - rWidth / 2, rCenter.Y - rHeight)
            };

            ffg.Segments.Add(new LineSegment(new Point(rCenter.X, rCenter.Y), true));
            ffg.Segments.Add(new LineSegment(new Point(rCenter.X + rWidth / 2, rCenter.Y - rHeight), true));
            ffg.Segments.Add(new LineSegment(new Point(rCenter.X - rWidth / 2, rCenter.Y - rHeight), true));
            flaggeo.Figures.Add(ffg);
            flaggeo.Freeze();

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

            drawingContext.DrawGeometry(rBrush, rPen, flaggeo);
            drawingContext.Close();
            _children.Add(drawingVisual);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 保存对象截图到ImageSource
        /// </summary>
        /// <param name="ui"></param>
        /// <param name="fileName"></param>
        /// <param name="pixelFormat"></param>
        public static RenderTargetBitmap ToImageSource(this FrameworkElement ui, PixelFormat pixelFormat)
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            //drawingVisual 的作用是校正Margin 和 Left Top
            using (DrawingContext context = drawingVisual.RenderOpen())
            {
                VisualBrush brush = new VisualBrush(ui)
                {
                    Stretch = Stretch.None
                };
                context.DrawRectangle(brush, null, new Rect(0, 0, ui.ActualWidth, ui.ActualHeight));
                context.Close();
            }
            //使用drawingVisual渲染
            RenderTargetBitmap bmp = new RenderTargetBitmap((Int32)ui.ActualWidth, (Int32)ui.ActualHeight, SystemDpiX, SystemDpiY, pixelFormat);

            bmp.Render(drawingVisual);
            return(bmp);
        }
Ejemplo n.º 23
0
        public static BitmapImage StringToBitmap(string str)
        {
            var text = new FormattedText(str,
                                         CultureInfo.GetCultureInfo("en-us"),
                                         FlowDirection.LeftToRight,
                                         new Typeface("Verdana"),
                                         30, System.Windows.Media.Brushes.Green);

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

            drawingContext.DrawRectangle(System.Windows.Media.Brushes.Transparent, null, new Rect(0, 0, 200, 100));
            drawingContext.DrawText(text, new System.Windows.Point(0, 0));
            drawingContext.Close();

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)text.Width, (int)text.Height, 100, 100, PixelFormats.Pbgra32);

            bmp.Render(drawingVisual);
            return(bmp.ToWinFormsBitmap().ToMediaBitmap());
        }
Ejemplo n.º 24
0
        public bool Draw()
        {
            if (_drawValid)
            {
                return(false);
            }
            DrawingContext dc = RenderOpen();

            try {
                var formattedText = GetFormattedText();

                Size = new Size(formattedText.Width, formattedText.Height);

                dc.DrawText(formattedText, new Point());
                _drawValid = true;
                return(true);
            } finally {
                dc.Close();
            }
        }
Ejemplo n.º 25
0
        public override void Perform()
        {
            TextFormatter formatter = TextFormatter.Create();
            ListBox       listBox   = new ListBox();

            DoubleAnimation anim = new DoubleAnimation(MinScale, MaxScale, TimeSpan.FromMilliseconds(AnimTime));

            anim.AutoReverse = true;
            ScaleTransform st = new ScaleTransform(MinScale, MinScale);

            for (int i = 0; i < TextToFormat.Length; i++)
            {
                TextSource.Text = TextToFormat[i];

                DrawingGroup   drawingGroup = new DrawingGroup();
                DrawingContext dc           = drawingGroup.Open();
                dc.PushTransform(st);
                GenerateFormattedText(TextSource, dc, formatter);
                dc.Close();

                Image        image        = new Image();
                DrawingImage drawingImage = new DrawingImage(drawingGroup);
                image.Source              = drawingImage;
                image.Stretch             = Stretch.None;
                image.HorizontalAlignment = HorizontalAlignment.Left;
                image.VerticalAlignment   = VerticalAlignment.Top;
                image.Margin              = new Thickness(1, 1, 1, 10);

                listBox.Items.Add(image);
            }

            st.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
            st.BeginAnimation(ScaleTransform.ScaleYProperty, anim);

            WindowSource.Width   = Microsoft.Test.Display.Monitor.Dpi.x * 9; // 9"
            WindowSource.Height  = Microsoft.Test.Display.Monitor.Dpi.y * 6; // 6"
            listBox.Height       = WindowSource.Height;
            WindowSource.Content = listBox;

            DispatcherHelper.DoEvents(AnimTime * 2);
        }
Ejemplo n.º 26
0
        protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
        {
            // Fill temporary graphics buffer with mask (currently always a rectangle).
            DrawingVisual dv = new DrawingVisual
            {
                Effect = new BlurEffect
                {
                    Radius     = Radius,
                    KernelType = KernelType.Gaussian
                }
            };
            DrawingContext dc = dv.RenderOpen();

            dc.DrawRectangle(new SolidColorBrush(SWMColors.Transparent), null, new Rect(0, 0, source.Width, source.Height));

            switch (Shape)
            {
            case FeatherShape.Rectangle:
                dc.DrawRectangle(new SolidColorBrush(SWMColors.White), null, new Rect(Radius, Radius, source.Width - Radius * 2, source.Height - Radius * 2));
                break;

            case FeatherShape.Oval:
                dc.DrawEllipse(new SolidColorBrush(SWMColors.White), null, new Point(source.Width / 2.0, source.Height / 2.0), source.Width / 2 - Radius * 2, source.Height / 2 - Radius * 2);
                break;

            default:
                throw new NotSupportedException();
            }
            dc.Close();

            RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(source.Width, source.Height);

            rtb.Render(dv);

            Brush alphaMask = new ImageBrush(rtb);

            return(new FeatherEffect
            {
                AlphaMask = alphaMask
            });
        }
Ejemplo n.º 27
0
        public static BitmapSource CaptureScreen(Visual target, int pixelWidth, int pixelHeight)
        {
            try
            {
                Logger.LogFuncUp();

                if (target == null || pixelWidth <= 0 || pixelHeight <= 0)
                {
                    return(null);
                }

                double dpiX = 96.0 * pixelWidth / (target as FrameworkElement).ActualWidth;
                double dpiY = 96.0 * pixelHeight / (target as FrameworkElement).ActualHeight;

                DrawingVisual drawingVisual = new DrawingVisual();
                using (DrawingContext context = drawingVisual.RenderOpen())
                {
                    VisualBrush brush = new VisualBrush(target)
                    {
                        Stretch = Stretch.None
                    };
                    context.DrawRectangle(brush, null, new Rect(0, 0, (target as FrameworkElement).ActualWidth, (target as FrameworkElement).ActualHeight));
                    context.Close();
                }


                //delete this capture method(the position if the grid changed, the capture will capture the wrong area)
                RenderTargetBitmap rtb = new RenderTargetBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32);
                rtb.Render(drawingVisual);
                //rtb.Render(target);

                Logger.LogFuncDown();

                return(rtb);
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
            }
            return(null);
        }
Ejemplo n.º 28
0
        public static void CreateBitmap(BitmapSource bgImage, string title, string savePath)
        {
            //创建一个RenderTargetBitmap 对象,将WPF中的Visual对象输出
            RenderTargetBitmap composeImage = new RenderTargetBitmap(bgImage.PixelWidth, bgImage.PixelHeight, bgImage.DpiX, bgImage.DpiY, PixelFormats.Default);

            FormattedText signatureTxt = new FormattedText(title,
                                                           System.Globalization.CultureInfo.CurrentCulture,
                                                           System.Windows.FlowDirection.LeftToRight,
                                                           new Typeface(System.Windows.SystemFonts.MessageFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
                                                           14,
                                                           System.Windows.Media.Brushes.Black);

            signatureTxt.MaxTextWidth = 110;

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

            drawingContext.DrawImage(bgImage, new Rect(0, 0, bgImage.Width, bgImage.Height));
            ////计算签名的位置
            //double x2 = (bgImage.Width / 2 - signatureTxt.Width) / 2;
            //double y2 = 10;
            drawingContext.DrawText(signatureTxt, new System.Windows.Point(15, 15));
            drawingContext.Close();
            composeImage.Render(drawingVisual);
            //定义一个JPG编码器
            JpegBitmapEncoder bitmapEncoder = new JpegBitmapEncoder();

            //加入第一帧
            bitmapEncoder.Frames.Add(BitmapFrame.Create(composeImage));
            string directoryPath = System.IO.Path.GetDirectoryName(savePath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            //保存至文件(不会修改源文件,将修改后的图片保存至程序目录下)
            using (FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.ReadWrite))
            {
                bitmapEncoder.Save(fileStream);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Draw the carrier
        /// </summary>
        /// <param name="drawingVisual"></param>
        override protected void Render(DrawingVisual drawingVisual)
        {
            DrawingContext drawingContext = drawingVisual.RenderOpen();
            //if (Grid == Carrier.undefinedGrid)
            //    return;

            //1 border
            int  xPos = GetBoundingRectXStart(_carrier.GridID);//
            int  yPos = GetBoundingRectYStart();
            Size sz   = new Size(_carrier.Dimension.XLength, _carrier.Dimension.YLength);

            Brush backGroundBrush = new SolidColorBrush(Color.FromArgb(128, _carrier.BackgroundColor.B, _carrier.BackgroundColor.G, _carrier.BackgroundColor.R));

            Color border = _isSelected ? Colors.Blue : Colors.Black;

            VisualCommon.DrawRect(xPos, yPos, sz, drawingContext, border, backGroundBrush);
            DrawGrid(this.Grid, drawingContext);


            //2 each site
            for (int i = 0; i < _carrier.Sites.Count; i++)
            {
                var fillBrsuh = new SolidColorBrush(Color.FromArgb(128, 255, 255, 255));
                var site      = _carrier.Sites[i];
                int xSite     = (int)(site.XOffset + xPos);
                int ySite     = (int)(site.YOffset + yPos);
                border = _isSelected ? Colors.Blue : Colors.Brown;
                bool bNeedHighLight = i == _highLightSiteIndex;

                Size tmpSZ = new Size(site.XSize, site.YSize);
                Rect rc    = new Rect(new Point(xSite, ySite), tmpSZ);
                if (bNeedHighLight)
                {
                    BlowUp(ref rc);
                    border    = Colors.DarkGreen;
                    fillBrsuh = new SolidColorBrush(Color.FromArgb(128, 255, 255, 0));
                }
                VisualCommon.DrawRect((int)rc.X, (int)rc.Y, rc.Size, drawingContext, border, fillBrsuh);
            }
            drawingContext.Close();
        }
Ejemplo n.º 30
0
        private void BackgroundGenerateImage()
        {
            GenerationMutex.WaitOne();
            try
            {
                MediaPlayer player = new MediaPlayer {
                    Volume = 0, ScrubbingEnabled = true
                };
                player.Open(new Uri(Path, UriKind.Relative));
                while (player.NaturalDuration.HasTimeSpan == false)
                {
                    ;
                }
                player.Position = TimeSpan.FromSeconds(player.NaturalDuration.TimeSpan.TotalSeconds / 2);
                System.Threading.Thread.Sleep(1000);

                RenderTargetBitmap rtb = new RenderTargetBitmap(320, 180, 96, 96, PixelFormats.Pbgra32);
                DrawingVisual      dv  = new DrawingVisual();
                DrawingContext     dc  = dv.RenderOpen();
                dc.DrawVideo(player, new Rect(0, 0, 320, 240));
                dc.Close();
                rtb.Render(dv);

                JpegBitmapEncoder encoder      = new JpegBitmapEncoder();
                MemoryStream      memoryStream = new MemoryStream();
                Image = new BitmapImage();
                encoder.Frames.Add(BitmapFrame.Create(rtb));
                encoder.Save(memoryStream);
                Image.BeginInit();
                Image.StreamSource = new MemoryStream(memoryStream.ToArray());
                Image.EndInit();
                Image.Freeze();
                memoryStream.Close();
                player.Close();
            }
            catch (Exception)
            {
                Image = DefaultImageGetter.Instance.Movie;
            }
            GenerationMutex.ReleaseMutex();
        }