在 WPF InkCanvas 中绘制基本形状

发布于 2024-09-08 04:30:05 字数 159 浏览 6 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终陌 2024-09-15 04:30:06

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.

怪我太投入 2024-09-15 04:30:06

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.

檐上三寸雪 2024-09-15 04:30:06

这里 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.

£冰雨忧蓝° 2024-09-15 04:30:06

这是一个简单的实现:

public void drawCircleAp(Double EHeight, Double EWidth, InkCanvas surface)
{
  Ellipse e1 = new Ellipse();
  e1.Width = EWidth;
  e1.Height = EHeight;
  var brush = new SolidColorBrush();
  brush.Color = Color.FromArgb(100, 0, 0, 0);
  e1.Stroke = brush;
  e1.StrokeThickness = 4;
  surface.Children.Add(e1);
}

Here is a simple implementation:

public void drawCircleAp(Double EHeight, Double EWidth, InkCanvas surface)
{
  Ellipse e1 = new Ellipse();
  e1.Width = EWidth;
  e1.Height = EHeight;
  var brush = new SolidColorBrush();
  brush.Color = Color.FromArgb(100, 0, 0, 0);
  e1.Stroke = brush;
  e1.StrokeThickness = 4;
  surface.Children.Add(e1);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文