Fifth chapter-delphi Graphic image Programming (i) (1)

Source: Internet
Author: User
Tags polyline

In Delphi, a set of objects and parts are defined to draw graphics and perform some simple image functions. Using these objects, parts of the method, can easily draw a variety of commonly used graphics, by setting their properties, you can get different styles of graphics. In addition, through the definition of mouse events, it is convenient to design a graphical drawing program.

This chapter describes the following:

1. Methods and attributes of the Tcanvas,tpen,tbrush,tcolor object;

2. The realization of drawing function;

3. Methods and properties of Timage,tpicture,tbitbtn,tbitmap parts;

4. Image observation and processing.

GRAPHEX.DPR is a simple graphical image application that is specific to these objects and components. This chapter will be described in conjunction with this procedure.

5.1 Drawing Objects Overview

5.1.1 Tcanvas Object (Canvas objects)

The Tcanvas object is a surface for drawing, in which the program implements various drawing functions, and the canvas properties of many parts (such as Timage,tmemo) are Tcanvas objects. Drawing a shape on a part is drawn on the part's canvas. The Tcanvas Brush,pen,font properties are Tbrush,tpen,tfont objects that define the style of drawing graphics. About the Tbrush,tpen object, described in detail in the next section.

The position of the canvas's pen is defined in the Penpos property, and the pen can be moved using the MoveTo method. If you want to output text on the canvas, you can use the TextOut method.

Tcanvas has many methods to accomplish the common drawing function, and now introduces the method and function as Table 5.1:

Table 5.1 Methods for Tcanvas objects

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Method Name Form and description

───────────────────────────────────────

Arc arc (X1,y1,x2,y2,x3,y3,x4,y4:integer);

The Arc method draws an arc on the ellipse, determined by the ellipse by (X1,y1), (X2,y2) at two.

Set The starting point of the arc is the intersection of the ellipse circumference and the center of the ellipse with the (x3,y3) connection. The end of the arc rectangle is the ellipse

The intersection of the circular Circle and the center of the ellipse with the (X4,Y4) line, and arcs in a counter-clockwise direction.

Chord chord (X1,y1,x2,yx,x3,y3,x4,y4:integer);

The chord method joins the two points on the ellipse, which are determined by the rectangle (x1,y1), (X2,y3) at two points

Set, (X3,Y3) is the starting point, (X4,Y4) is the endpoint.

Brushcopy brushcopy (const dest:trect; Bitmap:tbitmap;const Source Trect;

Color:tcolor);

The Brushcopy method copies a portion of a bitmap to a rectangular area of the canvas and replaces the color of the bitmap with the current color of the brush. Parameter dest defines a rectangular area of the canvas that fills the bitmap, bitmap defines the bitmap, and the source defines the rectangular area of the bitmap on which the bitmap

is copied; The color that replaces the bitmap in a color definition brush.

Copyrect Copyrect (dest:trect; Canvas:tcanvas; Source trect);

This method copies part of the image to the canvas from another canvas object. Canvas represents the source canvas, and source is the area of the image to be copied on the source canvas. Dest indicates that replication will be accepted on the target canvas

The rectangular area of the image.

Draw Draw (X,y:integer; Graphic:tgraphic);

This method graphic the image given by the pixel point coordinate (x,y) of the canvas, which can be a bitmap, an icon, or a meta bitmap.

Ellips ellips (X1,y1,x2,y2:integer);

The Ellips method draws an ellipse on the rectangular boundary specified by the canvas (x1,y1) is the pixel coordinate of the upper-left corner of the rectangle, and the x2,y2 is the pixel coordinate of the lower-right corner of the rectangle. If the rectangle forms an area, an ellipse appears.

LineTo LineTo (X,y:integer);

LineTo draws a line from the current position to the position specified by (x,y) and moves the pen position to (x, y).

MoveTo MoveTo (X,y:integer);

MoveTo sets the current position of the pen to Point (x,y) where the current position of the pen is in the Penpos property.

Change the current position of the pen using the MoveTo method, do not try to change the value of the Penpos.

Die Die (X1,y1,x2,y2,x3,y3,x4,y4:longint);

The Die method draws part of the ellipse, as determined by the rectangle specified by the point (X1,y1), (X2,y2), which is determined by the two rays of the Ellipse Center to (x3,y3), (X4,y4) two.

Polygon Polygon (Points:array of Tprint);

The Polygon method draws a series of points on the canvas, connecting each point to a line at the end, forming an area with the current brush to fill the area with two points.

Polyline polyline (Ports:array of Tport);

The Polyline method draws a series of points on the canvas with the current brush, and the dots are connected sequentially.

Stretchdraw Stretchdraw (Const Rect:TRcct:Graphic:TGraphic);

This method rect an image in the rectangle specified by the parameter. The image extends to resize to fit the rectangle.

Rectangle Rectangle (X1,y1,x2,y2:integer);

The rectangle method draws a rectangle on the canvas with the current brush, (X1,Y1) is the upper-left corner of the rectangle, (x2,y2) is the lower-right corner of the rectangle.

Romlrect Romlrect (x1,y1,x2,y2,x3,y3,: Integer);

Drawfocuserect

DrawFocusRect (Const rect:trect)

This method draws a rectangle to indicate that the rectangle receives focus. This method is an XOR function, and the original rectangle disappears when the second call. The drawfocuserect drawn rectangle cannot be scrolled. To implement scrolling, call this method to make the rectangle disappear and redraw after scrolling.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

5.1.2 Tpen Object (Brush objects)

Application common Tpen objects draw various segments on the canvas, and the color of the pen is defined in the Colors property. The width of the segment is defined in the Width property.

The Style property defines the various types of segments, such as Table 5.2:

The value and meaning of table 5.2 styled

━━━━━━━━━━━━━━━━━━━━━━

Style meaning

──────────────────────

Psolod Draw Fixed Segment

Psdash a line segment made up of underscores.

Psdot a segment composed of dots.

Psdashdot Draw Dot Dash

Psclear Draw Double Dot Dash

Psclear the invisible segment of the picture

Psinsideframe rectangular wireframe with border drawing

━━━━━━━━━━━━━━━━━━━━━━━

The Mode property defines the color of the segment. You can redefine the color of a line segment by combining the current color, screen color, or their inverse value, but not changing a color property. See table 5.3 for details.

The value and meaning of the table 5.3 mode

━━━━━━━━━━━━━━━━━━━━━━━━━━━

Mode pixel Color

──────────────────────────

Pmblack Black

Pmwhite White

Pmnop, no change.

Pmcopy using colors in the Color property

Inverse value of pmnotcopy pen color

The combination of the color of the Pmmergepennot pen and the screen color reversal value

Pmnasknotpen screen color and pen color

Combination of pmmergenotpen screen colors and pen color reversal values

━━━━━━━━━━━━━━━━━━━━━━━━━━━

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.