开发者

How to convert a shape from Directx to gdi+ using c#

开发者 https://www.devze.com 2022-12-18 09:53 出处:网络
i draw the circle in c# using directx.i like to draw the circle with same dimensions in c# using GDI.It means i like to convert that circle from directx to GDI. Is any body help for me.plz provide the

i draw the circle in c# using directx.i like to draw the circle with same dimensions in c# using GDI.It means i like to convert that circle from directx to GDI. Is any body help for me.plz provide the answer f开发者_Python百科or me.how can i do it.Is any algorithm available for that........ And also i give the input for center of the circle is (x,y)in this point format.but in gdi it is pixel format .so how can i convert the directx points to gdi+ pixels


Here is a link from MSDN that introduces Graphics and Drawing in Windows Forms. And it's likely that you will need something similar to:

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);

}

After that you might want to look into double-buffering techniques, a few links :

  • [SO] How to double buffer .NET controls on a form?
  • [MSDN] Double Buffered Graphics
  • [MSDN] Using Double Buffering
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号