. NET3.5 GDI + graphics operation 4

Source: Internet
Author: User

10.3 Basic Drawing

Graphics in. NET include the following two steps.

First, create the Graphics object.

Second, use the Graphics object to draw lines and shapes, render text, or display an action image.

Thus, how to create a Graphics object is the first problem to be solved. This section describes how to draw basic graphics such as lines, rectangles, circles, and so on, and then basic graphics form complex graphics. Graphics commonly used drawing methods are shown in the following table.

10.3.1 Create a drawing object

There are several ways to create a drawing object.

² receives a reference to a drawing object in the Paint event of a form or control as part of a PaintEventArgs. This method is typically used to get a reference to a drawing object when you create the drawing code for the control.

² invokes the CreateGraphics method of a control or form to get a reference to a Graphics object that represents the drawing surface of the control or form. You can use this method if you want to draw on a form or control that already exists.

² Creates a Graphics object from any object inherited from image. This method is commonly used to generate pictures.

In the case of ASP.net Web applications, the first two are not possible, so only a third method can be used.

Suppose you want to create a drawing object from the site root mm.jpg graphic, you can use the following code:

Bitmap bmp = new Bitmap(Server.MapPath("~/mm.jpg"));
Graphics g = Graphics.FromImage(bmp);
bmp.Dispose();
g.Dispose();

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.