×

GDI+和GDI的一些基本图形描绘方法函数对比

Kalet Kalet 发表于2009-03-20 12:00:14 浏览203 评论0

抢沙发发表评论



GDI+和GDI的一些基本图形描绘方法函数对比





GDI+



GDI



// 清空背景

SolidBrush brush(Color(255, 255,255,255));








using namespace Gdiplus;

pGraphics->FillRectangle(&brush,0,0,m_winWidth,m_winHeight);




// 画笔准备

int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;

Pen pen(Color(255, 0, 0, 255), PenWidth);

Pen pen2(Color(255, 255, 0, 0), PenWidth);






//-------------------------------------------

// 画对角线

pGraphics->DrawLine(&pen,pRect->left,pRect->top,pRect->right, pRect->bottom);

pGraphics->DrawLine(&pen,pRect->right,pRect->top,pRect->left, pRect->bottom);


//-------------------------------------------

// 画格子

for (int y = 0; y < m_winHeight; y += 10) {

    pGraphics->DrawLine(&pen, 0, y, m_winWidth, y);

}


for (int x = 0; x < m_winWidth; x += 10) {

    pGraphics->DrawLine(&pen, x, 0, x, m_winHeight);

}





//-------------------------------------------

// 画圆弧

pGraphics->DrawArc(&pen2, 0,0, 100,100, 0.0f,360.0f);























//-------------------------------------------

//画填充多边形

SolidBrush fillPolyBrush(Color(128, 255, 0, 0));

Point point1(100, 100);

Point point2(200, 130);

Point point3(250, 160);

Point point4(150, 200);

Point point5( 70, 130);

Point points[5] = {point1, point2, point3, point4, point5};

pGraphics->FillPolygon(&fillPolyBrush, points, 5);







//-------------------------------------------

// 字符串

if (theApp.m_optionDlg.m_strDrawString != "") {

// UNICODE 字串变换

_bstr_t bstr(theApp.m_optionDlg.m_strDrawString );


Font myFont(L"Arial", 42);

PointF origin( 0.0f, 0.0f);





SolidBrush blackBrush(Color(255, 0, 0, 0));

StringFormat format;

format.SetAlignment (StringAlignmentCenter);



pGraphics->DrawString(

bstr,

bstr.length(),

&myFont,

origin,

&blackBrush);

}



// 清空背景

CBrush brush;

brush.CreateSolidBrush (RGB(255, 255, 255)); 

//初始画刷保存

CBrush OrigBrush;

CBrush *pTmpBrush = (CBrush*)pDC->SelectObject(brush);

OrigBrush.FromHandle ((HBRUSH)pTmpBrush);


pDC->Rectangle(pRect);

pDC->SelectObject(&OrigBrush);

brush.DeleteObject ();

        

// 画笔准备

int PenWidth = theApp.m_optionDlg.m_iSliderPenWidth;

CPen pen(PS_SOLID, PenWidth, RGB(0, 0, 255));

CPen pen2(PS_SOLID, PenWidth, RGB(255, 0, 0));

//初始画笔保存

CPen OrigPen;

CPen *pTmpPen = (CPen*)pDC->SelectObject(pen);

OrigPen.FromHandle ((HPEN)pTmpPen);


//-------------------------------------------

// 画笔准备

pDC->MoveTo(pRect->left, pRect->top);

pDC->LineTo(pRect->right, pRect->bottom);

pDC->MoveTo(pRect->right, pRect->top);

pDC->LineTo(pRect->left, pRect->bottom);


//-------------------------------------------

// 画格子

for (int y = 0; y < m_winHeight; y += 10) {

pDC->MoveTo(0, y);

pDC->LineTo(m_winWidth, y);

}

for (int x = 0; x < m_winWidth; x += 10) {

pDC->MoveTo(x, 0);

pDC->LineTo(x, m_winHeight);

}

pDC->SelectObject(&OrigPen);

pen.DeleteObject ();        


//-------------------------------------------

// 画圆弧

long width, height;

POINT     cpos;

double    r,srad,erad;

const double m_pi = 3.1415926535758932;


width = 100 - 0;

height = 100 - 0;

cpos.x = 0 + (long)(width / 2.0);

cpos.y = 0 + (long)(height / 2.0);

r = max(width / 2.0, height / 2.0);

srad = 0.0 * m_pi / 180.0;

erad = (0.0 + 360.0) * m_pi / 180.0;

pTmpPen = (CPen*)pDC->SelectObject(pen2);

pDC->Arc(0,0, 100,100,

cpos.x + (long)(r * cos(srad)),

cpos.y + (long)(r * sin(srad)),        

cpos.x + (long)(r * cos(erad)),

cpos.y + (long)(r * sin(erad)));

pDC->SelectObject(&OrigPen);

pen2.DeleteObject ();       




//-------------------------------------------

//画填充多边形

CBrush fillPolyBrush;

fillPolyBrush.CreateSolidBrush (RGB(255, 0, 0)); 

pTmpBrush = (CBrush*)pDC->SelectObject(fillPolyBrush);

CPoint point1(100, 100);

CPoint point2(200, 130);

CPoint point3(250, 160);

CPoint point4(150, 200);

CPoint point5( 70, 130);

CPoint points[5] = {point1, point2, point3, point4, point5};

pDC->Polygon(points, 5);

pDC->SelectObject(&OrigBrush);

fillPolyBrush.DeleteObject ();


//-------------------------------------------

// 符串

if (theApp.m_optionDlg.m_strDrawString != "") {

//UNICODE 字串变换

_bstr_t bstr(theApp.m_optionDlg.m_strDrawString );


CFont myFont;

CFont OrigFont;

myFont.CreatePointFont (420, "Arial");

CFont *pTmpFont = (CFont*)pDC->SelectObject(myFont);

OrigFont.FromHandle ((HFONT)pTmpFont);

                  

CBrush blackBrush;

blackBrush.CreateSolidBrush (RGB(0, 0, 0)); 

pTmpBrush = (CBrush*)pDC->SelectObject(blackBrush);

//pDC->SetTextAlign(TA_CENTER);


pDC->TextOut(0, 0, bstr, bstr.length());

pDC->SelectObject(&OrigFont);

myFont.DeleteObject();

}



GDI+与GDI绘图函数的对比

































GDI+



GDI



备注


GDI+和GDI的一些基本图形描绘方法函数对比

轮廓线



填充



 



 



DrawArc



-



Arc



圆弧



-



-



AngleArc



线段和圆弧



-



-



ArcTo



椭圆的圆弧



-



-



Chord



圆弧和线段组成的半月形



DrawEllipse



FillEllipse



Ellipse



圆和椭圆



DrawPie



FillPie



Pie



扇形



DrawLine



-



LineTo MoveToEx



从现在位置开始到终点的直线



DrawLines



-



Polyline PolyLineTo



一组线段组成的线段群



-



-



PolyPolyline



一组线段群



DrawPolygon



FillPolygon



Polygon



多边形



-



-



PolyPolygon



一组多边形



DrawBezier 



-



-



4个点定义的贝塞尔曲线



DrawBeziers



-



PolyBezier PolyBezierTo



一个以上的贝塞尔曲线



DrawPath



FillPath



FillPath



路径



DrawRectangle



FillRectangle



Rectangle



矩形



DrawRectangles



FillRectangles



-



一组矩形



-



-



RoundRect



圆弧端角的矩形



-



FillRegion



PaintRgn  FillRgn



Region 内部填充



DrawString



-



TextOut



字符串



DrawClosedCurve



FillClosedCurve



-



闭合 Curve曲线



DrawCurve



-



-



Curve 曲线



DrawIcon



-



-



在指定坐标处绘制由指定的 Icon 对象表示的图像。



DrawIconUnstretched



-



-



Icon 对象表示的图像,而不缩放该图像。



DrawImage



-



StretchBlt StretchDIBits



在指定位置并且按原始大小绘制指定的 Image 对象



DrawImageUnscaled



-



BitBlt


GDI+和GDI的一些基本图形描绘方法函数对比

在由坐标对指定的位置,使用图像的原始物理大小绘制指定的图像。



群贤毕至

访客