C# WPF如何用DrawVisual绘制填充颜色的三角形?

DrawingVisualdrawingVisual=newDrawingVisual();DrawingContextdrawingContext=drawingVis... DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
Rect rect = new Rect(new Point(0,0), new Size(X, Y));
Brush bc = new SolidColorBrush(Colors.LightBlue);
drawingContext.DrawRectangle(bc, (Pen)null, rect);
drawingContext.DrawText(new FormattedText("LightBlue", CultureInfo.CurrentCulture,FlowDirection.LeftToRight, new Typeface("微软雅黑"), (int)Y / 32, Brushes.White),new Point((int)X / 25, (int)Y / 21));
drawingContext.Close();
var rtbitmap = new RenderTargetBitmap(X, Y, 0.0, 0.0, PixelFormats.Default);
rtbitmap.Render(drawingVisual);
image1.Source = rtbitmap;
展开
 我来答
龍过鸡年
2012-12-18 · TA获得超过311个赞
知道小有建树答主
回答量:308
采纳率:100%
帮助的人:371万
展开全部
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Image Grid.Column="0">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#A0ADD8E6">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="50,50,200,200"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#A0FFC0CB">
<GeometryDrawing.Geometry>
<EllipseGeometry Center="100,100" RadiusX="80" RadiusY="80"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Geometry="M 150,150 L 300,150 150,300 z" Brush="#A000FFFF"/>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>

<Rectangle Grid.Column="1">
<Rectangle.Fill>
<VisualBrush>
<VisualBrush.Visual>
<Grid Background="White">
<Rectangle Fill="LightBlue" Opacity=".5"/>
<TextBlock Foreground="White" FontSize="48" Opacity=".5" Text="LightBlue"/>
<Path Fill="Red" Data="M 0,0 L 100,0 0,100 z" Opacity=".5"/>
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式