標籤:
一 Windows畫圖
1 圖形繪製
1.1 圖形繪製的方式
擷取到畫圖的控制代碼,裝置描寫敘述符(DC)。使用對應的畫圖API。在裝置上繪製圖形
1.2 顏色
RGB,每種顏色8位,共24位顏色
32位顏色:顏色數量24為顏色,多出的8位表示灰階。
16位:顏色數量是2的16次方。
Win32下。顏色的定義使用 COLORREF。RGB的宏定義顏色
COLORREF nColor = RGB( 0, 0, 0 ); 黑色
COLORREF nColor = RGB( 255, 255, 255 ); 白色
COLORREF nColor = RGB( 255, 255, 255 ); 紅色
從一個顏色值中擷取RGB三色:
int nRed = GetRValue( DWord rgb )
int nGreen = GetGValue( DWord rgb )
int nBlue = GetBVakue( DWord rgb )
1.3 點的繪製和擷取
繪製: SetPixel
COLORREF SetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos, // y-coordinate of pixel
COLORREF crColor // 顏色值
);
擷取: GetPixel
COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel);
1.4 直線的繪製
MoveToEx移動當前點到指定位置
LineTo 從當前點繪製之前到指定位置
1.5 弧的繪製
Arc和AngleArc提供不同的繪製弧的方式
BOOL AngleArc( HDC hdc, // handle to device context int X, // x-coordinate of circle‘s center 圓心x座標 int Y, // y-coordinate of circle‘s center 圓心y座標 DWORD dwRadius, // circle‘s radius 園的半徑 FLOAT eStartAngle, // arc‘s start angle開始角度 FLOAT eSweepAngle // arc‘s sweep angle夾角);
圓弧的分割方式
int SetArcDirection(
HDC hdc, // handle to device context int ArcDirection // new arc direction);
BOOL Arc( HDC hdc, // handle to device context int nLeftRect, // x-coord of rectangle‘s upper-left corner int nTopRect, // y-coord of rectangle‘s upper-left corner int nRightRect, // x-coord of rectangle‘s lower-right corner int nBottomRect, // y-coord of rectangle‘s lower-right corner 外切矩形的座標 int nXStartArc, // x-coord of first radial ending point int nYStartArc, // y-coord of first radial ending point int nXEndArc, // x-coord of second radial ending point int nYEndArc // y-coord of second radial ending point);
1.6 折線
BOOL Polyline( HDC hdc, // handle to device context CONST POINT *lppt, // array of endpoints int cPoints // number of points in array);
BOOL PolylineTo( HDC hdc, // handle to device context CONST POINT *lppt, // array of points DWORD cCount // number of points in array); 與PolyLine類似, 在繪製PolyLine前。從當前點使用LineTo繪製直線到Polyline的第一個頂點
BOOL PolyPolyline( HDC hdc, // handle to device context CONST POINT *lppt, // array of points 全部點的數組 CONST DWORD *lpdwPolyPoints, // array of values 每組點的數量 DWORD cCount // number of entries in values array 分組的數量);
1.7 Bizer曲線
BOOL PolyBezier( HDC hdc, // handle to device context CONST POINT* lppt, // endpoints and control points 點數組 DWORD cPoints // count of endpoints and control points 點的數量
);
1.8 圓角矩形
BOOL RoundRect( HDC hdc, // handle to DC int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect, // y-coord of lower-right corner of rectangle int nWidth, // width of ellipse 產生圓角的橢圓的寬度 int nHeight // height of ellipse 產生圓角的橢圓的高度);
1.9 矩形
BOOL Rectangle( HDC hdc, // handle to DC int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect // y-coord of lower-right corner of rectangle);
1.10 橢圓
BOOL Ellipse( HDC hdc, // handle to DC int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect // y-coord of lower-right corner of rectangle);
1.11 pie餅
BOOL Pie( HDC hdc, // handle to DC int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect, // y-coord of lower-right corner of rectangle int nXRadial1, // x-coord of first radial‘s endpoint int nYRadial1, // y-coord of first radial‘s endpoint int nXRadial2, // x-coord of second radial‘s endpoint int nYRadial2 // y-coord of second radial‘s endpoint);
1.12 弦
BOOL Chord( HDC hdc, // handle to DC int nLeftRect, // x-coord of upper-left corner of rectangle int nTopRect, // y-coord of upper-left corner of rectangle int nRightRect, // x-coord of lower-right corner of rectangle int nBottomRect, // y-coord of lower-right corner of rectangle int nXRadial1, // x-coord of first radial‘s endpoint int nYRadial1, // y-coord of first radial‘s endpoint int nXRadial2, // x-coord of second radial‘s endpoint int nYRadial2 // y-coord of second radial‘s endpoint);
1.13 多變形
BOOL Polygon( HDC hdc, // handle to DC CONST POINT *lpPoints, // polygon vertices int nCount // count of polygon vertices);
2 GDI畫圖對象 - 畫筆
2.1 畫筆的作用
能夠控制線條的顏色、樣式、寬度
2.2 畫筆的使用
建立畫筆
CreatePen
置成當前DC能夠使用的畫筆
SelectObject
繪製圖形
從當前DC中取出畫筆
SelectObject
銷毀畫筆
DeleteObject
3 GDI畫圖對象 - 畫刷
3.1 畫刷的作用
填充封閉圖形,包含樣式 顏色
3.2 畫刷的使用
建立畫刷
CreateSilidBrush
CreateHatchBrush
置成當前DC能夠使用的畫刷
SelectObject
繪製圖形
取出畫刷
SelectObject
銷毀畫刷
DeleteObject
Win32 Windows編程 十