用GDI+画长方体

本文详细介绍了如何利用GDI+在Windows应用程序中绘制出逼真的三维长方体,包括坐标转换、颜色填充和边框描绘等关键步骤,适合初学者掌握图形绘制技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// "cuboid.png"
void DrawCuboid(CDC *pDC)
{
Graphics graphics(pDC->m_hDC);
Point point1(50, 50); //    2       3
Point point2(100, 20);// 1      7
Point point3(200, 20);//
Point point4(50, 250);//
Point point5(150, 250);//           6
Point point6(200, 220);//4      5
Point point7(150,50);  //
// front :1,7,5,4
    Point frontPoints[4]={ point1 , point7 , point5, point4};
    RectF frontRect((float)point1.X,(float)point1.Y,
 (float)(point7.X-point1.X),
 (float)(point5.Y-point7.Y));
LinearGradientBrush frontB(frontRect,Color::Blue,Color::Aqua,LinearGradientModeHorizontal);// = 90.0f);//
graphics.FillPolygon(&frontB,frontPoints,4);
// right :7,3,6,5
    RectF rightRect((float)point7.X,(float)point7.Y,
 (float)(point3.X-point7.X),
 (float)(point5.Y-point3.Y));
    Point rightPoints[4]={ point7 , point3 , point6, point5};
LinearGradientBrush b(rightRect,Color::Aqua,Color::Blue,LinearGradientModeHorizontal);// = 90.0f);//
graphics.FillPolygon(&b,rightPoints,4);
// top :1,2,3,7
INT count = 4;
GraphicsPath rectPath;
    Point topPoints[4]={ point1 , point2 , point3, point7};
rectPath.AddPolygon(topPoints, count);
//
PathGradientBrush pathBrush(&rectPath);
//
Color cols[] = {Color::Blue, Color::Blue, Color::Blue, Color::Blue};
pathBrush.SetSurroundColors(cols, &count);
pathBrush.SetCenterColor(Color::Aqua);
pathBrush.SetCenterPoint(point7);
graphics.FillPolygon(&pathBrush, topPoints, count);
// draw  contour
Pen bluePen( Color(255,0,0,255),1);
Point points[6] = { point1 , point2 , point3, point6, point5, point4 };
graphics.DrawPolygon(&bluePen,points,6);
// draw 3 lines
graphics.DrawLine(&bluePen,point1,point7 );
graphics.DrawLine(&bluePen,point7,point3);
graphics.DrawLine(&bluePen,point5,point7);

}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值