网学网为需要ASP.net的朋友们搜集整理了Visual C++.NET GDI+编程基础相关资料,希望对各位网友有所帮助!
CPaintDC dc(this); using namespace Gdiplus; Graphics graphics( dc.m_hDC ); graphics.SetPageUnit(UnitMillimeter); Pen newPen( Color( 255, 0, 0 ), 3 ); HatchBrush newBrush( HatchStyleCross, Color(255, 0, 255, 0), Color(255, 0, 0, 255)); graphics.DrawRectangle( &newPen, 50, 50, 100, 60); graphics.FillRectangle( &newBrush, 50, 50, 100, 60); |
... graphics.SetPageUnit(UnitMillimeter); graphics.SetPageScale( (REAL)0.1); Pen newPen( Color( 255, 0, 0 ), 3 ); ... |
Pen newPen( Color( 255, 0, 0, 255 ), 3 ); Pen newPen(Color( 0, 0, 255), 3); // 当Color只有三个实参时,颜色Alpha分量值为255。 Pen newPen(Color::Blue, 3); COLORREF crRef = RGB( 0, 0, 255); Color color; color.SetFromCOLORREF(crRef); Pen newPen(color, 3); |
using namespace Gdiplus; Graphics graphics( pDC->m_hDC ); Pen pen(Color(255, 0, 0, 255), 15); pen.SetDashStyle(DashStyleDash); graphics.DrawLine(&pen, 0, 50, 400, 150); pen.SetDashStyle(DashStyleDot); graphics.DrawLine(&pen, 0, 80, 400, 180); pen.SetDashStyle(DashStyleDashDot); graphics.DrawLine(&pen, 0, 110, 400, 210); |
Status SetDashPattern( const REAL* dashArray, INT count); |
REAL dashVals[4] = { 2, // 短划长为2 2, // 间隔为2 15, // 短划长为15 2}; // 间隔为2 Pen pen(Color(255, 0, 0, 0), 5); pen.SetDashPattern(dashVals, 4); graphics.DrawLine(&pen, 5, 20, 405, 200); |
using namespace Gdiplus; Graphics graphics( pDC->m_hDC ); Pen pen( Color( 255, 0, 0, 255 ), 15); pen.SetStartCap(LineCapFlat); pen.SetEndCap(LineCapSquare); graphics.DrawLine(&pen, 50, 50, 250, 50); pen.SetStartCap(LineCapRound ); pen.SetEndCap(LineCapRoundAnchor); graphics.DrawLine(&pen, 50, 100, 250, 100); pen.SetStartCap(LineCapDiamondAnchor); pen.SetEndCap(LineCapArrowAnchor); graphics.DrawLine(&pen, 50, 150, 250, 150); |
SolidBrush( const Color& color); HatchBrush( HatchStyle hatchStyle, const Color& foreColor, const Color& backColor); |
LinearGradientBrush(Point & point1, Point & point2, Color & color1, Color & color2); LinearGradientBrush(Rect & rect, Color & color1, Color & color2, REAL angle, BOOL isAngleScalable); LinearGradientBrush(Rect & rect, Color & color1, Color & color2, LinearGradientMode mode); |
PathGradientBrush(const GraphicsPath* path); PathGradientBrush(const Point * points, INT count, WrapMode wrapMode); |
Graphics graphics( pDC->m_hDC ); GraphicsPath path; // 构造一个路径 path.AddEllipse(50, 50, 200, 100); // 使用路径构造一个画刷 PathGradientBrush pthGrBrush(&path); // 将路径中心颜色设为蓝色 pthGrBrush.SetCenterColor(Color(255, 0, 0, 255)); // 设置路径周围的颜色为蓝芭,但alpha值为0 Color colors[] = {Color(0, 0, 0, 255)}; INT count = 1; pthGrBrush.SetSurroundColors(colors, &count); graphics.FillRectangle(&pthGrBrush, 50, 50, 200, 100); LinearGradientBrush linGrBrush( Point(300, 50), Point(500, 150), Color(255, 255, 0, 0), // 红色 Color(255, 0, 0, 255)); // 蓝色 graphics.FillRectangle(&linGrBrush, 300, 50, 200, 100); |
Graphics graphics( pDC->m_hDC ); Image image(L"image.jpg"); TextureBrush tBrush(&image); Pen texturedPen(&tBrush, 10); graphics.DrawLine(&texturedPen, 25, 25, 325, 25); tBrush.SetWrapMode(WrapModeTileFlipXY); graphics.FillRectangle(&tBrush, 25, 100, 300, 200); |
Graphics graphics( pDC->m_hDC ); Pen pen(Color(255, 0, 0, 255)); Matrix matrix; matrix.Translate(40, 0); // 先平移 matrix.Rotate(30, MatrixOrderAppend); // 后旋转 graphics.SetTransform(&matrix); graphics.DrawEllipse(&pen, 0, 0, 100, 50); |
Graphics graphics( pDC->m_hDC ); Pen pen(Color::Blue,3); graphics.DrawLine(&pen, 150,50,200,80); pen.SetColor(Color::Gray); Matrix matrix( -1,0,0,1, 150,50); // 使用第一种情况 graphics.SetTransform(&matrix); graphics.DrawLine(&pen, 0,0,50,30); |
Matrix( REAL m11, REAL m12, REAL m21, REAL m22, REAL dx, REAL dy); |
绘图函数 | 功能描述 |
DrawArc | 绘制一条圆弧曲线,范围由起止角大小决定,大小由矩形或长宽值指定 |
DrawBezier | 绘制一条由一系列型值顶点决定的三次Bezier曲线 |
DrawBeziers | 绘制一系列的三次Bezier曲线 |
DrawClosedCurve | 绘制一条封闭的样条曲线 |
DrawCurve | 绘制一条样条曲线 |
DrawEllipse | 绘制一条椭圆轮廓线,大小由矩形或长宽值指定 |
DrawLine | 绘制一条直线 |
DrawPath | 绘制由GraphicsPath定义的路径轮廓线 |
DrawPie | 绘制一条扇形(饼形)轮廓线 |
DrawPolygon | 绘制一个多边形的轮廓线 |
DrawRectangle | 绘制一个矩形 |
FillEllipse | 填充一个椭圆区域 |
FillPath | 填充一个由路径指定的区域 |
FillPie | 填充一个扇形(饼形)区域 |
FillPolygon | 填充一个多边形区域 |
FillRectangle | 填充一个矩形区域 |
FillRectangles | 用同一个画刷填充一系列矩形区域 |
FillRegion | 填充一个区域(Region)的内部 |
Graphics graphics( pDC->m_hDC ); Pen pen(Color::Blue, 3); Point point1( 50, 200); Point point2(100, 150); Point point3(160, 180); Point point4(200, 200); Point point5(230, 150); Point point6(220, 50); Point point7(190, 70); Point point8(130, 220); Point curvePoints[8] = {point1, point2, point3, point4, point5, point6, point7, point8}; Point* pcurvePoints = curvePoints; GraphicsPath path; path.AddClosedCurve(curvePoints, 8, 0.5); PathGradientBrush pthGrBrush(&path); pthGrBrush.SetCenterColor(Color(255, 0, 0, 255)); Color colors[] = {Color(0, 0, 0, 255)}; INT count = 1; pthGrBrush.SetSurroundColors(colors, &count); graphics.DrawClosedCurve(&pen, curvePoints, 8, 0.5); graphics.FillPath(&pthGrBrush, &path); |