2. ؟ نا ل
ھ دا ا ن و د دهButton ال ھ ھ اول
رزم ا ھ ا Pixels ال ھ رة ا ا ھ
//Create New BitMap Image To Put Pixels In And Set Its Width And Height
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
ا ا رة ھ نا ا هفا اPictureBox زي ط ل و ض ال رة و ط لا
Pixelsرة ك فا رزم وھ اا ھ
//Fill BMP Image Pixels With Points On The Line
bmp.SetPixel(x, y, Color.Red);
PictureBoxف ال رة ا رزم ھ ا
//Show BMP Image In The PictureBox
Graphics g = pictureBox1.CreateGraphics();
g.DrawImage(bmp, new Point(0, 0));
*************************************************************************
ده
Direct Line Algorithm
ر عا ا ده ا
3. Drag & Dropل ھ
دهDraw Line ب اButton ال ھ
ه اھ ا ما ا وده
private void btnDraw_Click(object sender, EventArgs e)
{
//Create New BitMap Image To Put Pixels In And Set Its Width And Height
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//Start Algorithm
// The Two Points Vertices
int x1 = int.Parse(txtX1.Text),
x2 = int.Parse(txtX2.Text),
y1 = int.Parse(txtY1.Text),
y2 = int.Parse(txtY2.Text);
//m >> Slope
double m = (x2 - x1) / (y2 - y1);
//b >> Intersection With Y
double b = y1 - (m * x1);
//Find All Points Between The Two Points
for (int x = x1; x <= x2; x++)
{
//From Line Equation >> (y = m*x + b)
int y = (int)(m * x + b);
//Fill BMP Image Pixels With Points On The Line
bmp.SetPixel(x, y, Color.Red);
}
//End Algorithm
//Show BMP Image In The PictureBox
Graphics g = pictureBox1.CreateGraphics();
g.DrawImage(bmp, new Point(0, 0));
}
و رب ا ن ا
م