Asp. NET Implementation Data Graph B

Source: Internet
Author: User
Tags definition
Asp.net| Data | Chart 3) How to draw and write on a picture:
Writing on a picture is done by the drawstring () method of the resulting "Graphic" object, and before calling this method, you must set the font and brush, which you call the method:



public void DrawString (
String S,
Font font,
Brush Brush,
float x,
Float y
) ;



"S" is the string to be output, "font" is the font of the string, "brush" is the definition brush, and the following two parameters are the position coordinates that produce the string. The specific statement that produces a string in the program is as follows:



Font axesfont = new Font ("Arial", 10);
Brush Blackbrush = new SolidBrush (Color. Red);
G. DrawString ("Write text on the picture, hehe", Axesfont, Blackbrush, 90, 20);


 
To draw lines on the picture to use the DrawLine () method of the "Graphic" object, use the following syntax:



public void DrawLines (
Pen Pen,
Point [] Points
) ;



Where "points" is the location of the definition point, of course, you can also use the method used in this article to invoke, that is, to define a line of each drawing, so I feel more method. Here are three lines drawn from the resulting picture:



Pen redpen = new Pen (Color. Red, 1);
Pen Blackpen = new Pen (Color. Blue, 2);
The following statement shows a variety of lines on this picture object that define the thickness, start, end, and so on of the line.
G. DrawLine (Blackpen, 0, 2, 210, 250);
G. DrawLine (Blackpen, 210, 250, 310, 50);
G. DrawLine (RedPen, 310, 50, 210, 350);



Know these basic knowledge, in the custom picture shape, the picture coloring, in the picture writes, draws the line to appear to be easier, the following code (chart2.aspx) function is customizes a square picture, and draws the line, writes, the color in the picture, concretely as follows:



<%@ Page Language = "C #" ContentType = "Image/jpeg"%>
<%@ Import Namespace = "System"%>
<%@ Import Namespace = "System.Drawing"%>
<%@ Import Namespace = "System.Drawing.Drawing2D"%>
<%@ Import Namespace = "System.Drawing.Imaging"%>
<script language = "C #" runat = "server" >
void Page_Load (object sender, EventArgs e)
{
Bitmap image = New Bitmap (400, 400);
Font axesfont = new Font ("Arial", 10);
Brush Blackbrush = new SolidBrush (Color. Red);
Pen redpen = new Pen (Color. Red, 1);
Pen Blackpen = new Pen (Color. Blue, 2);
Graphics g = Graphics. FromImage (image);
G. Clear (Color. White);
G. FillRectangle (New SolidBrush, Color. LightGreen), 0, 0, 400, 400);
In this picture object to draw a picture, you can define the text size, position, color, etc.
G. DrawString ("Write text on the picture, hehe", Axesfont, Blackbrush, 90, 20);
The following statement shows a variety of lines on this picture object that define the thickness, start, end, and so on of the line.
G. DrawLine (Blackpen, 0, 2, 210, 250);
G. DrawLine (Blackpen, 210, 250, 310, 50);
G. DrawLine (RedPen, 310, 50, 210, 350);
Save this Picture object in "Jpeg" format and display it on the client
Image. Save (Response. OutputStream, ImageFormat. JPEG);
Image. Save (Response. OutputStream, ImageFormat. JPEG);
}
</script >
<body >
</body >





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.