在 WPF InkCanvas 中绘制基本形状
我正在 wpf 中开发类似绘画的应用程序。我希望用户能够在图像或平面上添加一些绘图。此外,我想绘制一些基本形状,如直线、椭圆形或矩形。我正在尝试使用一个 inkcanvas,我可以在其中徒手绘画,但我不能像在油漆中那样绘制形状。任何人都可以指导我并提供一些有关如何做的线索。请帮助我。任何输入将不胜感激。
I am working on a paint like application in wpf.I want the users to be able to add some drawings over images or plain surfaces.Also i want to draw some basic shapes like line,ellipse or a rectangle.I am trying to work with an inkcanvas,where i can do freehand drawing,but i cant draw shapes like in paint.Can anyone guide me and provide some clues on how to do it.Please help me on this.Any inputs will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
InkCanvas 中有两种集合:
Strokes,它们由 StylusPoints 组成并由 DrawingAttributes 定义。这就是墨水,由鼠标或手写笔绘制。
另一个是Children,它可以包含FrameworkElements。例如,椭圆形是一个 Shape 是一个 FrameworkElement。
尝试使用 yourCanvas.Children.Add(ellipse) 并看看效果如何。当然没有理由仅仅因为您还想使用预定义的形状而回避 InkCanvas。
不过,值得指出的是,InkCanvas 的弟弟 InkPresenter 没有 Children 属性。而 Silverlight 就只有这一点。
There are two sorts of collections in an InkCanvas:
Strokes, which are composed of StylusPoints and defined by DrawingAttributes. That's what the Ink is, as drawn by a mouse or stylus.
The other is Children, which can contain FrameworkElements. Ellipse, for instance, is a Shape is a FrameworkElement.
Try playing around with yourCanvas.Children.Add(ellipse) and see how you go. There is certainly no reason to shy away from the InkCanvas just because you also want to use predefined shapes.
It's worth pointing out, though, that the InkCanvas's little brother, the InkPresenter, does NOT have a Children property. And Silverlight only has that one.
WPF 提供了一个 Shape 类,其中包含可用于绘制形状的预构建方法。不要使用 inkcanvas,而是直接在画布上绘制。
WPF provides a Shape class that includes prebuilt methods that you can draw shapes with. Don't use the inkcanvas and instead draw directly to a canvas.
这里 http://ciintelligence.blogspot.com/2011/ 07/silverlight-drawing-tool-silver-draw.html
您可以找到更好的控件,它改进了 SilverDraw 控件并具有额外的功能:
特点是:
* 您可以绘制基本形状,也可以使用手绘铅笔绘制。
* 您可以删除绘图。
* 您可以撤消和重做绘图。
* 可以在服务器端将绘图保存为jpeg。
Here http://ciintelligence.blogspot.com/2011/07/silverlight-drawing-tool-silver-draw.html
you can find better control which improved SilverDraw control with extra features:
Freatures are:
* You can draw basic shapes and also can draw using freehand pencil.
* You can erase drawing.
* You can undo and redo drawing.
* Can save drawing as jpeg in server side.
这是一个简单的实现:
Here is a simple implementation: