这里是我的代码,我想实现DDA算法,而不使用c#中的drawLine方法。我试图使用PutPixel方法,但它不起作用。我的窗户没有任何东西。有没有什么办法可以在c#中使用drawLine方法画线?不使用DrawLine方法的绘制线
private void Form1_Paint(object sender, PaintEventArgs e)
{
grafik = e.Graphics;
DDACiz(ilk.X, ilk.Y, ikinci.X, ikinci.Y, grafik, Color.DarkRed);
}
void PutPixel(Graphics g, int x, int y, Color c) // sadece bir pixel icin
{
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(10, 10);
bm.SetPixel(0, 0, Color.DarkRed);
g.DrawImageUnscaled(bm, x, y);
}
void DDACiz(int x1, int y1, int x2, int y2,Graphics grafik, Color renk)
{
int PikselSayisi;
int dx, dy;
float x, xFark;
float y, yFark;
dx = x2 - x1;
dy = y2 - y1;
PikselSayisi = Math.Abs(dx) > Math.Abs(dy) ? Math.Abs(dx) : Math.Abs(dy);
xFark = (float)dx/(float)PikselSayisi;
yFark = (float)dy/(float)PikselSayisi;
x = (float)x1;
y = (float)y1;
while (PikselSayisi!=0)
{
PutPixel(grafik,(int)Math.Floor(x + 0.5F),(int) Math.Floor(y + 0.5f),renk);
x += xFark;
y += yFark;
PikselSayisi--;
}
}
}
}
'我尝试使用PutPixel方法,但它不工作,如果你的问题出现在这个方法中,删除从你的问题不必要的代码。 http://sscce.org/ – EZI 2015-04-02 21:57:12
要使用Graphics对象绘制像素,您需要使用'FillRectangle(yourBrush,x,y,1,1)' – TaW 2015-04-02 21:57:14