【问题标题】:Efficient way to draw a single point on canvas在画布上绘制单点的有效方法
【发布时间】:2016-04-08 01:17:07
【问题描述】:

我正在寻找一种在 C# 画布上绘制单个点(带有颜色)的方法。 在 android 中我会做类似

paint.Color = Color.Rgb (10, 10, 10);
canvas.DrawPoint (x, y, paint);

所以我以为我可以在Shape class 中找到它,但它不在那里。我错过了什么还是没有办法画出一个点?

在第二种情况下,推荐的绘制点的方法是什么?在 HTML5 画布中存在类似的问题,人们正在使用 rectangles/circles 绘制点。

P.S.一个标题相似的问题 Add Point to Canvas 没有回答它并进入“如何绘制形状”。

【问题讨论】:

  • 您使用的是什么 UI 库?窗体? WPF?地铁?还有什么?
  • 也许画一条很小的线?
  • 指向什么?你应该去那里画一个椭圆。
  • @Amu 他只想填充一个像素。

标签: c# windows-phone-7


【解决方案1】:

我刚刚为 UWP 遇到了同样的问题,我最终决定使用 Ellipse:

int dotSize = 10;

Ellipse currentDot = new Ellipse();
currentDot.Stroke = new SolidColorBrush(Colors.Green);
currentDot.StrokeThickness = 3;
Canvas.SetZIndex(currentDot, 3);
currentDot.Height = dotSize;
currentDot.Width = dotSize;
currentDot.Fill = new SolidColorBrush(Colors.Green);
currentDot.Margin = new Thickness(100, 200, 0, 0); // Sets the position.
myGrid.Children.Add(currentDot);

【讨论】:

  • 嗨,myGrid 是什么?您是说 YourCanvas 吗?
  • 嗨 FirstStep,它实际上是 XAML 中 Canvas 内的一个 Grid 对象:` ` 但你可能可以直接在画布中绘制,没有时间测试,但如果不可能,我会感到惊讶。
  • 我明白你的意思,只是想确认一下,谢谢
【解决方案2】:

折线呢?

xaml:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Canvas x:Name="canvas" Background="#00FFFFFF" MouseMove="Canvas_MouseMove">
        <Polyline x:Name="polyline" Stroke="DarkGreen" StrokeThickness="3"/>
    </Canvas>
</Grid>

c#:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    polyline.Points.Add(new Point(0,0));
    polyline.Points.Add(new Point(0, 1));
    polyline.Points.Add(new Point(1, 0));
    polyline.Points.Add(new Point(1, 1));
}

【讨论】:

    猜你喜欢
    • 2020-11-23
    • 1970-01-01
    • 2013-06-26
    • 2012-05-04
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    相关资源
    最近更新 更多