WPF -- Graphics draws a straight line and saves it as bitmap, wpfbitmap
The solution is to draw a vertex set into a straight line and save it as a bitmap.
First, determine the bitmap width and height based on the maximum value of the coordinate of the point set:
Bitmap bmp = new Bitmap (width, height );
Create a Graphics-type object to create the image Graphics g = Graphics. FromImage (bmp );
Then draw a line with the g object (the drawline method determines a line at two points). The first parameter represents the color of the line, and the second and third parameters are the initial and adjacent points, respectively;
Finally, call the save method of bmp to save the image;
A simple example is as follows:
List<System.Drawing.Point> Points = new List<System.Drawing.Point>() { new System.Drawing.Point() { X=10,Y=20}, new System.Drawing.Point() { X = 10, Y = 20 }, new System.Drawing.Point() { X = 20, Y = 30 }, new System.Drawing.Point() { X = 40, Y = 50 }, new System.Drawing.Point() { X=50,Y=60}, new System.Drawing.Point() { X=70,Y=80}, new System.Drawing.Point() { X=90,Y=100}, new System.Drawing.Point() { X=100,Y=120} }; Bitmap bmp = new Bitmap(200, 200); Graphics g = Graphics.FromImage(bmp); for (int i = 0; i < Points.Count-1; i++) { var vector3dstart = Points[i]; var vector3dend = Points[i + 1]; g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.SaddleBrown), vector3dstart, vector3dend); } bmp.Save(@"C:/X.bmp");