将 XAML 形状绘制到 DrawingContext?
我有几个由 WPF 形状基元组成的常见符号(例如矩形、直线、路径等)。这些符号当前作为用户控件存储在 xaml 文件中。例如:
<Canvas x:Name="Symbol" Width="100" Height="100">
<Rectangle x:Name="Rectangle" Width="100" Height="100" Stretch="Fill">
<Rectangle.Fill>
<SolidColorBrush Color="Aqua"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
上面是一个简单的例子,但我的大多数符号都比较复杂,由许多不同的部分组成。因此,我希望使用这些用户控件来存储符号并使它们易于操作。
我正在 Canvas 的 OnRender 方法中进行大量绘图,并希望在绘图中包含其中一些复合符号。是否可以将它们转换为某种格式以将它们绘制到 DrawingContext?我知道有一个名为 DrawingContext.DrawImage 的方法,但这需要 ImageSource 作为输入。
任何想法将不胜感激。
谢谢, 艾伦
I have several common symbols that have been composed of WPF shape primatives (e.g. Rectangle, Line, Path etc). These symbols are currently stored in xaml files as user controls. For example:
<Canvas x:Name="Symbol" Width="100" Height="100">
<Rectangle x:Name="Rectangle" Width="100" Height="100" Stretch="Fill">
<Rectangle.Fill>
<SolidColorBrush Color="Aqua"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
The above is a simple example but most of my symbols are more complex and composed of many different parts. So, I was hoping to use these user controls to store the symbols and make them easy to manipulate.
I am doing quite a bit of drawing in the OnRender method of a Canvas and would like to include some of these composite symbols in my drawing. Is it possible get these into a format to draw them to the DrawingContext? I am aware that there is a method called DrawingContext.DrawImage but this takes an ImageSource as input.
Any ideas would be much appreciated.
Thanks,
Alan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将画布制作成图像源,则可以使用drawimage,例如:
You can use drawimage if you make your canvas into an imagesource like: