C # Use GDI to draw a coordinate chart (negative values are supported)

Source: Internet
Author: User

To facilitate project printing, use GDI to draw a fully-coordinate system diagram and embed a PDF file.

As follows:

 

Generally, a coordinate chart only has 1/4 in the upper right corner. This graph is fully coordinate, and the input is the coordinates of four points, which can be negative values.

Code:

Code Bitmap bitmap = new Bitmap (this. Width, this. Height, PixelFormat. Format24bppRgb );
Graphics g = Graphics. FromImage (bitmap );
// Graphics g = this. CreateGraphics ();
G. Clear (Color. White );
Font font = new Font (Font. Name, 11 );
SolidBrush brush = new SolidBrush (Color. Black );
Pen pen = new Pen (Color. Black );
Pen. EndCap = LineCap. ArrowAnchor;
Pen. DashStyle = DashStyle. Solid;
// Coordinate axis
Point pCenter = new Point (300,260 );
G. DrawLine (pen, new Point (pCenter. X-200, pCenter. Y), new Point (pCenter. X + 200, pCenter. Y); // x
G. DrawLine (pen, new Point (pCenter. X, pCenter. Y + 200), new Point (pCenter. X, pCenter. Y-200); // y
// Axis mark
For (int I = 0; I <5; I ++)
{
G. drawLine (Pens. black, new Point (pCenter. x-iX * I, pCenter. y), new Point (pCenter. x-iX * I, pCenter. y-4); // x
G. DrawString (-I). ToString (), font, brush, new PointF (pCenter. X
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.