GDI+繪制漸變色


 

例1:

void CTextDlg::OnPaint()
{
Graphics graphics(this->m_hWnd);

LinearGradientBrush linGrBrush(
  Point(0,0),
  Point(200,0),
  Color(255,255,0,0),
  Color(255,0,0,255));

graphics.FillRectangle(&linGrBrush, 0, 0, 200, 200);
}

 

例2:

Graphics graphics(dc.GetSafeHdc());
graphics.Clear(Color::White);

//定義三種參與漸變的色彩
Color colors[] =
{
Color::Red, // 紅色
Color::Green,//過渡色為綠色
Color::Blue // 藍色
};

float positions[] =
{
0.0f, // 由紅色起
0.3f, // 綠色始於畫刷長度的三分之一
1.0f // 到藍色止
};

//構造一條從黑色到白色的漸變畫刷
LinearGradientBrush linGrBrush(
Point(0, 0),
Point(180, 0),
Color::Black,Color::White);

//設置漸變畫刷的多色漸變信息
//linGrBrush.InterpolationColors=clrBlend;
linGrBrush.SetInterpolationColors(colors, positions, 3);
//使用多色漸變畫刷填充目標區域
graphics.FillRectangle(&linGrBrush, 0, 0, 180, 100);

//使用普通的方法實現多色漸變
//由紅到綠,長度60
LinearGradientBrush linGrBrush1(
Point(0, 0),
Point(60, 0),
Color::Red,
Color::Green);

//由綠到藍,長度120
LinearGradientBrush linGrBrush2(
Point(60, 0),
Point(181, 0),
Color::Green,
Color::Blue);

//分別使用兩個畫刷填充兩個相鄰區域,形成多色漸變
graphics.FillRectangle(&linGrBrush1, 0, 120, 60, 100);
graphics.FillRectangle(&linGrBrush2, 60, 120, 120, 100);






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM