Graphics foundation
See the money
2005-4-16
The graphics device interface (GDI: Graphics Device Interface) is a subsystem of Windows, which is responsible for displaying graphics on the display and printer.
GDI consists of hundreds of function calls and some related data types, which are included in the GDI32.DLL dynamic connection library. The GDI command accesses the display and printer device via the device driver. GDI supports graphically independent of equipment.
Graphics output devices are divided into two categories: grating equipment and vector devices. The display, the printer is a grating device that represents an image in a point mode. Vector devices use line to draw images.
The graphic type displayed on the screen or printer itself can be divided into several categories, commonly referred to as "primitive". They are:
u Line and curve lines are the foundation of all vector graphics drawing systems. The current brush drawn in the line device description table.
U Fill Area When a series of lines or curves enclose a region, the region can be filled with the current GDI brush object. The painting can be a color, pattern or bitmap.
u Bitchart bitmap is a rectangular array of bit. These bit correspond to the pixels on the device, which are the foundation of the raster graphics. GDI supports two types of bitmaps: Old "devices related" bitmaps, GDI objects; new "device-independent" bitmaps, can be stored in disk files.
u Text
Unable to simply classify others:
u Mapping mode and transformation default in pixels
The set of GDI commands stored in binary forms in binary form
u Regional shape arbitrary composite regions
u path GDI's collection of straight lines and curves. The path can be used for drawing, filling, and cutting, and can also be converted to the area.
u Tailor drawing can limit in some part of the client area, this is the so-called tailoring. Tailor usually defined by a region or path.
u Pattern custom palette is typically limited to a display of 256 colors. 236 colors except 20 systems can be changed.
To draw on a graphics output device (display or printer), you must first get a device description table handle. The device description table contains many of the current "properties" that determines how the GDI function works on the output device.
The most commonly used acquisition and release device description table handle is to process becom_paint messages, call beginpaint and endpaint; call GETDC and ReleaseDC (Drawing Area as Window Customer Area) and getWindowDC and ReleaseDC when processing non-WM_PAINT messages The area is the entire window).
The device description table of BeginPaint, GetDC and GetWindow is related to the window on the display. Getting the device description The table has a more common function is CREATEDC:
HDC = CREATEDC (Pszdriver, Pszdevice, PSzoutput, PDATA);
...
DELETE (HDC);
The following calls can get the entire screen device description table handle:
HDC = CREATEDC (Text ("Display", NULL, NULL, NULL, NULL);
Call the CREATEIC function can obtain an information description table and cannot use it to draw graphics.
Call the CreateCompATIBLEDC function Create a memory device descriptor that is compatible with the specified device, the display surface is only one monochrome pixel width and height. Therefore, a bitmap of a reasonable width and height must be selected to draw a memory device descriptor before drawing, and then draws on the bitmap using the GDI function.
Call the CreateMetAfile function creation paid file:
HDCmeta = CREATEMETAFILE (PFileName);
...
HMF = Closemetafile (HDCMeta); a device description table typically represents a physical display device. Call the getDeviceCaps function to get information about the device.
The printer represents the resolution in "pixel per inch"; the display represents the resolution as the number of pixels in the horizontal and vertical directions, such as 1024 × 768. Call getSystemMetrics and getDeviceCaps can get the number of screen pixels. The font size is generally expressed in "pounds".
One pound
Approximately equal to 1/72 inches. Why is it?
10 pounds
Font, still divide the big font and small font? In general, it is assumed that the display resolution is 96 pixels per inch, and when the large font is selected, it is assumed to be 120 pixels per inch. Therefore, the higher the screen resolution, the smaller the same font.
A pixel color value can be represented in 1 bit, 8 bits, 16 bits or 24 bits. GetDeviceCaps returns the number of color bits for each pixel on the specified device. Generally use the ColorRef type to represent color values, it is a 32-bit unsigned long integer, represents red, green, and blue value from 0-24 bits per 8 digits, respectively.
The following table lists the basic attributes of the device descriptor and how to obtain and set each property:
Device content attribute default value modification function of the value of the acquired function Mapping ModeMM_TEXTSetMapModeGetMapModeWindow Origin (0, 0) of the value SetWindowOrgExOffsetWindowOrgExGetWindowOrgExViewport Origin (0, 0) SetViewportOrgExOffsetViewportOrgExGetViewportOrgExWindow Extents (1, 1) SetWindowExtExSetMapModeScaleWindowExtExGetWindowExtExViewport Extents (1, 1) SetViewportExtExSetMapModeScaleViewportExtExGetViewportExtExPenBLACK_PENSelectObjectSelectObjectBrushWHITE_BRUSHSelectObjectSelectObjectFontSYSTEM_FONTSelectObjectSelectObjectBitmapNoneSelectObjectSelectObjectCurrent Position (0, 0 ) MoveToExLineToPolylineToPolyBezierToGetCurrentPositionExBackground ModeOPAQUESetBkModeGetBkModeBackground ColorWhiteSetBkColorGetBkColorText ColorBlackSetTextColorGetTextColorDrawing ModeR2_COPYPENSetROP2GetROP2Stretching ModeBLACKONWHITESetStretchBltModeGetStretchBltModePolygon Fill ModeALTERNATESetPolyFillModeGetPolyFillModeIntercharacter Spacing0SetTextCharacterExtraGetTextCharacterExtraBrush Origin (0, 0) SetBrushOrgExGetBrushOrgExClipping RegionNoneSelectObjectSelectC LipRgnintersectClipRGnoffSetClipRgnexCludeclipRectSelectclippathGetClipbox
Before the registration window class, if you specify the CS_OWNDC style in the window style, each window will have a device descriptor alone; if you specify a CS_CLASSDC style in the window style, each window will share. A device descriptor; if both the two styles are not included, a temporary device descriptor is returned. SaveDC and RESTOREDC functions are used to save or restore some properties of the device description table when a state is restored. The getpixel and setpixel functions are used to read, write a pixel.
Lineto painting line
Polyline and POLYLINETO draw a set of straight lines
Polypolyline painted multiple groups
ARC and Arcto
Polybezier and Polybezierto painted Bayer spline
Rectangle drawn rectangle
Ellipse painting ellipse
RoundRect painting
PIE painting pie
Chord painting
There is a "current position" property in the device description table, and the line starting point is indicated when drawing straight. Call GetCurrentPositionEx to get this property.
Rectangle, Ellipse, etc. Draw a function of a closed area graphics, while drawing the lines, you will also use the brushing enclosed area.
Three rules that should be noted with GDI objects:
l After using it, you must delete your own GDI object.
l Prohibition of deleting GDI objects used in valid device description tables
l Prohibition of deleting the original GDI object
Create a PEN object:
HPEN = CREATEPEN (IpenStyle, iWidth, CRCOLOR);
Logpen logpen;
HPEN = CREATEPENIIRECT (& Logpen);
Delete a PEN object:
DeleteObject (HPEN);
Returns the properties of the PEN object:
GetObject (HPEN, SIZEOF (Logpen), (LPVOID) & logpen;
Returns the PEN object in the device description table:
HPEN = GetCurrentObject (HDC, OBJ_PEN);
Set the PEN mode:
SETROP2 (HDC, IdrawMode); / / Pen color and target pixel color to a bit Boolean operation
Set background mode:
SetBKMode (HDC, Transparent);
Set background color:
SetBkcolor (HDC, CRCOLOR);
Create a brush object:
Hbrush = Createsolidbrush (crcolor); // Entity painting
Hbrush = CreateHatchBrush (Ihatchstyle, CRCOLOR); // Back view
Hbrush = creagepatternbrush (hbmp); // bit picture brush
Hbrush = createdibpatternbrush (HBMP); // Device does not have a bit drawing brush
Hbrush = CREATEBRUSHINDIRECT (& Logbrush);
"Mapping Method" is an almost impact on device description table properties of all customer district drawings. Almost all GDI functions use "logical unit"; and all non-GDI functions use "device units (ie pixel units)." All equipment coordinates
Both are in pixels, the value on the X-axis is incremented from left to right, and the value on the Y-axis is incremented from top to bottom.
The equipment coordinates can generally be divided into three: l screen coordinates with the origin of the upper left corner, call CREATEDC to return. For CreateWindow, Movewnidow, a function that is independent of the window,,, GetMessagePos, GetCursorpos, WindowFromPoint, etc.
l The window coordinates are the origin in the upper left corner of the window, and the getWindowDC returns. It is generally not used.
l The customer zone coordinates in the upper left corner of the customer zone, call GETDC to return. ClientTScreen and ScreenToClient functions mutual conversion between client zone coordinates and screen coordinates.
Viewport coordinates based on the equipment coordinate system; Windoworg coordinates based on logical coordinate systems. Regardless of the window origin and how to change, the equipment coordinate original (0, 0) is always the top left corner of the screen, window, and customer area. Therefore, regardless of the VIEWPORT coordinate value or the Windoworg coordinate value, it is essentially the origin value of the logical coordinate system. Set the viewpoint equal to the origin of the logical coordinate of the device coordinate system. Setting the window origin is equal to the origin of the logical coordinate of the logical coordinate system.
SetViewPortorgex (HDC, 10, 20, NULL) maps device points (10, 20) into logical points (0, 0);
Setwindoworgex (HDC, 10, 20, NULL) maps logical points (10, 20) to device points (0,0);
The area is a description of the display on the display, this range is a combination of rectangles, polygons, and ellipses. The area can be used to draw and cut, by selecting the area to select the device description table, you can use the zone to perform a section (that is, the plot range is limited to a part of the client area).
Create a zone:
HRGN = CreateRectrgn (XLEFT, YTOP, XRIGHT, YBOTTOM);
HRGN = CREATEPOLYGONRGN (& Point, Icount, iPolyFillMode);
Combination area:
IRGNTYPE = Combinergn (HDESTRGN, HSRCRGN, HSRCRGN1, ICOMBINE);
Several regional selection of device descriptions:
SelectObject (HDC, HRGN); or SELECTCLIPRGN (HDC, HRGN);