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; 展开
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; 展开
1个回答
展开全部
<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>
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询