2012-07-27 103 views

回答

1
  • 繪製邊界進入圖像比邊界本身稍大。
  • 模糊它。
  • 清除邊框內部。
  • 在模糊圖像上繪製邊框。
  • 將該圖像繪製到目的地。
1

使用GDI +,我會建議你使用PathGradientBrush。它允許您在邊緣周圍填充一系列顏色的區域,這些顏色都會向中心顏色混合。在這種情況下,您可能只需要1種邊緣顏色。爲圓角矩形創建的GraphicsPath和使用FillPath()用PathGradientBrush來填補它:

GraphicsPath graphicsPath; 

//rect - for a bounding rect 
//radius - for how 'rounded' the glow will look 
int diameter = radius * 2; 

graphicsPath.AddArc(Rect(rect.X, rect.Y, diameter, diameter) 180.0f, 90.0f); 
graphicsPath.AddArc(Rect(rect.X + rect.Width - diameter, rect.Y, diameter, diameter), 270.0f, 90.0f); 
graphicsPath.AddArc(Rect(rect.X + rect.Width - diameter, rect.Y + rect.Height - diameter, diameter, diameter), 0.0f, 90.0f); 
graphicsPath.AddArc(Rect(rect.X, rect.Y + rect.Height - diameter, diameter, diameter), 90.0f, 90.0f); 
graphicsPath.CloseFigure(); 

PathGradientBrush brush(&graphicsPath); 
brush.SetCenterColor(centerColor); //would be some shade of blue, following your example 
int colCount = 1; 
brush.SetSurroundColors(surroundColor, &colCount); //same as your center color, but with the alpha channel set to 0 

//play with these numbers to get the glow effect you want 
REAL blendFactors[] = {0.0, 0.1, 0.3, 1.0}; 
REAL blendPos[] = {0.0, 0.4, 0.6, 1.0}; 
//sets how transition toward the center is shaped 
brush.SetBlend(blendFactors, blendPos, 4); 
//sets the scaling on the center. you may want to have it elongated in the x-direction 
brush.SetFocusScales(0.2f, 0.2f); 

graphics.FillPath(&brush, &graphicsPath); 
+0

相似,但效果不太一樣,我想...我無法控制發光的有條不紊......謝謝你 – toki 2012-07-31 12:06:37