Torna al Thread

private void prova() { this.pictureBox1.Image = null; Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(bmp); Pen redPen = new Pen(Color.Red, 1 / g.DpiX); redPen.Width = 2; g.TranslateTransform(1, 1.0f); g.PageUnit = GraphicsUnit.Pixel; StreamReader sr = new StreamReader("TextFile1.txt"); string[] coordinate; int x = 0; int y = 0; int x1 = 0; int y1 = 0; string txt = "Disegnata linea: ({0},{1}:{2},{3})"; while (!sr.EndOfStream) { coordinate = sr.ReadLine().Split(','); // tra apici va il carattere che separa i valori x = Convert.ToInt32(coordinate[0]); // convertiamo in valori numerici interi, ma DrawLine accetta anche float y = Convert.ToInt32(coordinate[1]); // convertiamo in valori numerici interi, ma DrawLine accetta anche float g.DrawLine(redPen, x1, y1, x, y); lbl.Text = string.Format(txt, x1, y1, x, y); x1 = x; // x1 contiene il valore x di partenza per la prossima linea y1 = y; // y1 contiene il valore y di partenza per la prossima linea } pictureBox1.Image = bmp; lbl.Text = "Fatto."; redPen.Dispose(); g.Dispose(); sr.Close(); sr.Dispose(); } }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5