Solution 2: To glow shapes by layering background color with alpha channel.
Note: You can use any out the next code piece, but SnapsToDevicePixels is not recommended to use:
RenderOptions.SetEdgeMode(canvas, EdgeMode.Aliased);
RenderOptions.SetBitmapScalingMode(canvas, BitmapScalingMode.NearestNeighbor);
canvas.SnapsToDevicePixels = true; // is not recommended to use.
canvas.UseLayoutRounding = true;
Code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
Canvas canvas;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
canvas = new Canvas();
canvas.Background = Brushes.Black;
this.Content = canvas;
Glow();
}
Geometry GetGeometry()
{
Path path = new Path();
path.Data = Geometry.Parse("M 50 50 200 50 125 200 Z");
return path.Data;
}
private void Glow()
{
int thickness = 30;
Color color = Colors.White;
byte add = (byte)(255 / thickness);
Geometry geom = GetGeometry();
for (int i = thickness; i > 0; )
{
color.A += add;
Geometry geom1 = geom.GetWidenedPathGeometry(new Pen(Brushes.Transparent, i--)).GetOutlinedPathGeometry();
{
Path path = new Path();
path.Data = geom1;
path.Fill = Brushes.Black;
canvas.Children.Add(path);
}
{
Path path = new Path();
path.Data = geom1;
path.Fill = new SolidColorBrush(color);
canvas.Children.Add(path);
}
}
}
}