5

C# キャンバスに 1 つの点 (色付き) を描画する方法を探しています。アンドロイドでは、私は次のようなことをします

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

なので、 Shapeクラスにあると思ったのですが、ありませんでした。何か足りないのですか、それとも単一の点を描く方法がありませんか?

2 番目の場合、推奨される点の描画方法は何ですか? HTML5 キャンバスにも同様の問題があり、人々は長方形/円を使用して点を描いています。

PS同様のタイトルのAdd Point to Canvasの質問は、それに答えておらず、「形状を描く方法」に移行しています。

4

2 に答える 2

4

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);
于 2016-04-07T16:52:35.813 に答える
1

ポリラインはどうですか?

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));
}
于 2014-02-14T14:03:33.907 に答える