这是我的代码,我想在不使用 c# 中的 drawLine 方法的情况下实现 DDA 算法。我尝试使用 PutPixel 方法,但它不起作用。我的窗户里什么都没有。有没有办法在c#中不使用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--;
}
}
}
}