2

这是我的矩形

protected void DrawRectangle(DrawingContext dc, Point point)
        {
            DrawingVisual drawingVisual = new DrawingVisual();
            using (DrawingContext drawContext = drawingVisual.RenderOpen())
            {
                Pen drawingPen = new Pen(ErrorBarBrush, ErrorBarThickness);
                dc.DrawRectangle(Brushes.Red,
                    new Pen(Brushes.Black, 5),
                    new Rect(new Point(point.X - 50, point.Y + 50),
                    new Point(point.X + 50, point.Y - 50)));
                dc.PushOpacity(2);

            }
        }

所以我的问题是如何设置我的不透明度,这是正确的方法吗?

4

2 回答 2

3

(这是改变矩形的不透明度)

不要将 Brushes.Red 传递给 Rectangle,而是创建一个新的 SolidColorBrush 并设置传递给 Rectangle 的 SolidColorBrush 的不透明度

SolidColorBrush rectBrush = new SolidColorBrush(Colors.Red);
rectBrush.Opacity = 0.5; // or whatever

dc.DrawRectangle(rectBrush, ...

你需要为 Pen 做类似的事情

于 2017-04-19T11:49:15.290 回答
1

简单地

drawingVisual.Opacity = 0.5;
于 2017-04-19T11:49:58.517 回答