WPF -- Graphics draws a straight line and saves it as bitmap, wpfbitmap

Source: Internet
Author: User

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");

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.