2010-01-27 109 views
1

我使用directx.i在c#中繪製圓形,就像使用GDI在c#中繪製具有相同尺寸的圓一樣。這意味着我喜歡將該圓形從directx轉換爲GDI。是任何身體的幫助me.plz爲我提供了答案,我可以做到這一點。是任何可用的算法........ 而且我給圓的中心輸入是(x, y)以這種格式。但在gdi中它是像素格式。因此,如何將directx點轉換爲gdi +像素如何將形狀從Directx轉換爲gdi +使用c#

+0

所以,就像澄清一樣,你有X,Y座標他的圈子的中心,你有半徑嗎?圓圈的中心是相關的,還是隻是想要有相似的形狀? – 2010-02-06 17:24:10

+0

你我有雙格式的半徑 – ratty 2010-02-08 04:33:47

+0

你想在哪繪製它?使用c的Windows面板中的 – 2010-02-08 05:18:21

回答

3

這是MSDN的一個鏈接,介紹Graphics and Drawing in Windows Forms。而且很可能,你將需要類似於:

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

} 

之後,你可能要考慮雙緩衝技術,幾個環節:

+0

這只是繪製gdi我不是問這個 – ratty 2010-02-09 06:49:03

+3

所以,你問香蕉,但不想要香蕉。我可以給你很多不是香蕉的東西... – 2010-02-09 13:50:05

+0

+1 Dynami:出色的工作! – IAbstract 2010-02-11 22:59:51