2012-07-27 59 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