我使用 directx 在 c# 中绘制圆。我喜欢使用 GDI 在 c# 中绘制具有相同尺寸的圆。这意味着我喜欢将该圆从 directx 转换为 GDI。有任何身体对我有帮助吗?请为我提供答案。我该怎么做。有任何可用的算法吗......我还给出了圆心的输入是(x,y)这种点格式。但在gdi中它是像素格式。那么我如何将directx点转换为gdi+像素

有帮助吗?

解决方案

这里有一个来自MSDN的链接,介绍了 Windows 窗体中的图形和绘图. 。您可能需要类似的东西:

public Form1()
{
    InitializeComponent();

    this.Paint += new PaintEventHandler(Form1_Paint);

    // This works too
    //this.Paint += (_, args) => DrawCircle(args.Graphics);  
}

void Form1_Paint(object sender, PaintEventArgs e)
{
    DrawCircle(e.Graphics);
}

private void DrawCircle(Graphics g)
{
    int x = 0;
    int y = 0;
    int radius = 50;

    // The x,y coordinates here represent the upper left corner
    // so if you have the center coordinates (cenX, cenY), you will have to
    // substract radius from  both cenX and cenY in order to represent the 
    // upper left corner.

    // The width and height represents that of the bounding rectangle of the circle
    g.DrawEllipse(Pens.Black, x, y, radius * 2, radius * 2);

    // Use this instead if you need a filled circle
    //g.FillEllipse(Brushes.Black, x, y, radius * 2, radius * 2);

}

之后,您可能想研究双缓冲技术,一些链接:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top