绘图一

1.定义点函数:

SetPixel(hDC,x,y,crColor); hDC为句柄,x,y为点坐标,crColor为颜色。

GetPixel(hDC,x,y)获取该点的像素点;

COLORREF crColor = GetPixel(hDC,x,y);

2.画直线:

a.利用MoveToEx函数和LineTo函数:

MoveToEx(hDC, x, y,NULL);//定义一个点,起点

LineTo(hDC,xEnd,yEnd); //连线到终点

b.利用Polyline函数:

//产生个矩阵

POINT apt[5]={100,100,200,100,200,200,100,200,100,100};

MoveToEx(hDC,apt[0].x,apt[0].y,NULL);

(1).for (int i=1;i<5;i++) LineTo(hDC,apt[i].x,apt[i].y);

(2).Polyline(hDC,apt,5);

(3).MoveToEx(hDC,apt[0].x,apt[0].y,NULL)'

      PolylineTo(hDC,apt+1,5);

(4).Rectangle(hDC,xLeft,yTop,xRight,yBottom);

//产生圆

Ellipse(hDC,xLeft,yTop,xRight,yBottom);

//圆角矩阵

RoundRect(hDC,xLeft,yTop,xRight,yBottom,xCornerEllipse,yCornerEllipse);

//弧形

Arc(hDC,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd);

//椭圆弓形

Chord(hDC,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd);

//扇形

Pie(hDC,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd);

3.彩图:

(1).创建画笔:CreatePen函数和CreatePenIndirect函数

        hPen = CreatePen(iPenStyle, iWidth, crColor);

  (2)选择画笔: SelectObject(hDc,hPen1);

 (3)删除画笔: DeleteObject(hPen1);    

case WM_PAINT:

HDC hDC;

PAINTSTRUCT ps;

HPEN hPen;//定义画笔

hDC=BeginPaint(hwnd,&ps);

LOGPEN logpen;//定义逻辑画笔

logpen.lopnStyle = PS_SOLID;//设置线型为实线

logpen.lopnWidth.x = 3; //设置画笔宽度

logpen.lopnColor = RGB(255,0,0);//设置直线为红色

hPen = CreatePenIndirect(&logpen);//

SelectObject(hDC,hPen);//选择画笔

Rectangle(hDC,100,100,300,300);//画矩阵

EndPaint(hwnd,&ps);

DeleteObject(hPen);//删除画笔

break;

4.颜色定义:

a.COLORREF RGB{

BYTEbyRed,

BYTEbyGreen,

BYTEbyBlue

};

调用方法为:COLORREF color = RGB(0,255,0)表示为绿色

b. RGB_value struct{

byte unused;

byte blue;

byte green;

byte red;}

 

posted @ 2016-08-05 20:46  xiaofeiyang  阅读(247)  评论(0编辑  收藏  举报