Title: Graphical Device Interface GDI
1Graphical Device Interface (GDI)
- High level interface to graphics engine.
- Functions to
- Obtain and release device contexts
- Obtain (e.g., GetTextMetrics) and set attributes
of device contexts (SetTextColor, SetTextAlign). - That work with GDI objects (e.g., logical pens,
logical brushes). - Primitives for drawing lines, curves, filled
areas, bitmaps, Text, etc. - To reduce complexity, many graphics attributes
are contained in device context.
2Color
- Three primary colors are Red, Green, and Blue.
- Each pixel has color based on the intensity of
each color. - full color display 24 bits per pixel. R8 G8
B8. - Can display 224th 16 Million.
- high color 16 bits per pixel. R5 G6 B5
- Can display 216th 64K colors.
- How many bits per pixel for 16 colors? 4.
- 24th 16.
- For 256 colors need 8 bits per pixel. (28th
256).
3Color Pallet
0
8 bit value
256
431..24 23..16 15..8 7..0 B G R
Predefined Macro RGB(0-255,0-255,0-255)
RGB(R,G,B) (0-255) RGB(255,255,255) White
RGB(0,0,0) Black RGB(255,255,0) Yellow
5SetPixel(hdc, x, y, RGB(0,0,0) Color
GetPixel(hdc, x, y) Lines Drawn from current
position maintained in DC. Want line from
startx, starty to endx, endy POINT pt
MovetoEx(startx, starty, pt) LineTo(hdc,
endx, endy) Now current position is endx,
endy.
6Filled functions Filled with current
area-filling brush. Rectangle(hdc, xleft, ytop,
xright, ybottom)
xleft xright
ytop ybottom
Filled with Current brush
7Filling Brush
- Not the brush associated with class
- Wndclass.hbrBackground .
- Can change brush, need handle to brush
- HBRUSH hBrush
- Several predefined
- LTGRAY_BRUSH
- GRAY_BRUSH
- BLACK_BRUSH
- NULL_BRUSH
8HBRUSH
- Not attribute of Device Context.
- Selected into DC.
- Hdc BeginPaint(hwnd, ps)
- hBrush GetStockObject(BLACK_BRUSH)
- OldBrush SelectObject(hdc, hBrush)
- Rectangle(hdc, xleft, ytop, xright, ybottom)
-
- Rectangle will be filled with black.
9Create Brush
- hBrush CreateSolidBrush(RGB(x,x,x))
- SelectObject(hdc, hBrush)
-
- Also create background out of various patterns
- hBrush CreateHatchBrush(Style, RGB(x,x,x))
- SelectObject(hdc, hBrush)
- Style HS_HORIZONTAL, HS_VERTICAL, ..
- DeleteObject(hBrush)
10Logical Pens
- current pen determines appearance of lines
- color, width, style.
- Default Black Pen one pixel wide.
- White Pen, Null Pen
- Need handle to a pen HPEN hPen, oldPen
- hPen GetStockObject(WHITE_PEN)
- oldPen SelectObject(hdc, hPen)
11Create Logical Pen
- HPEN hPen
- hPen CreatePen(Penstyle, width, RGB(x,x,x))
- Penstyle
- PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT,
- PS_NULL
- Width
- 0 1 pixel. If style is dotted or dashed, and
width gt 1, will draw solid. - Must select into device context.
12Raster Operations
- Appearance of lines is function of pen and
drawing mode. - Windows performs a bitwise Boolean operation
between pixels of pen and pixels of display
surface.
13Raster operation.
- Since involves only two pixel patterns is binary
raster operation or ROP2. - Drawing mode is attribute of device context.
14Drawing Modes
- Default R2_COPYPEN. Copies from pen onto
display. - Also
- R2_COPYBLACK Draws black line regardless of
color in pen or display. - R2_NOP Leaves display unchanged regardless of
color of pen or display.
15P 1 1 0 0 Boolean Op Drawing Mode D 1
0 1 0
0 0 0 0
0 R2_BLACK
1 1 1 1
1 R2_WHITE
0 0 1 1
P R2_NOTCOPYPEN
0 0 0 1
(P D) R2_NOTMERGEPEN
D R2_NOT
0 1 0 1
P R2_COPYPEN
1 1 0 0
16Setting Mode