最简单的GDI+程序代码

来源:互联网 发布:乐器演奏软件 编辑:程序博客网 时间:2024/06/08 09:51

void CTestGdiplusDlg::OnBnClickedButton1()
{
 //
 CPaintDC* pDC = new CPaintDC(this);
 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);
}

运行结果如下:

原创粉丝点击