GDI+和GDI的一些基本图形描绘方法函数对比
2011-03-23 10:36
435 查看
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 备注轮廓线 填充
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的一些基本图形描绘方法的对比
- GDI+和GDI的一些基本图形描绘方法的对比
- GDI图形图形的一些函数
- C#File类常用的文件操作方法(创建、移动、删除、复制等) File类,是一个静态类,主要是来提供一些函数库用的。静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和
- 一些基本的GDI操作BITMAP的方法
- 一些最基本的python方法和函数
- 使用C#制做进程监视器 (一些基本的方法函数)
- C++ string类的一些函数方法
- 少特化一个函数 基本类型与类类型的区别方法
- PHP中CURL方法curl_setopt()函数的一些参数
- 网络配置的一些基本命令和方法
- 介绍一些javascript基本函数
- Java常用的一些多媒体文件基本操作方法简介
- 一些最基本的开发设计原则方法(整理)
- C语言基础(1.linux终端命令2.gcc过程3.命令行模式和输入模式切换4.命令行一些命令5.函数(三要素)6.基本的C语言代码结构)
- 礼拜四log~java函数replaceAll报错解决方案 & 一些常用jq方法 & java函数addAll
- matlab画图入门篇--各种基本图形绘制的函数与实例【转载】
- 【Tensorflow】Tensorflow一些常用基本概念与函数(2)
- for循环打印一些基本图形
- python thread的一些基本函数