I am creating a simple DXF generator (used by CNC machines) which works with letters only and I am having a problem using the PathGradientBrush with the GraphicsPath class. I'm drawing the outline of a letter using the GraphicsPath afterwhich I need the corresponding GraphicsPath filled with a gradient, something similar to this:
As you can see, the gradient needs to start from the edges and then transition to white color in the center. This is code that I am currently using:
private void Form1_Paint(object sender, PaintEventArgs e) {
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
using(GraphicsPath Path = new GraphicsPath()) {
Path.AddString("I", Font.FontFamily, (int) FontStyle.Regular, 250f, Point.Empty, StringFormat.GenericTypographic);
using(Pen OutlinePen = new Pen(Color.Black, 1f)) {
e.Graphics.DrawPath(OutlinePen, Path);
using(PathGradientBrush FillBrush = new PathGradientBrush(Path)) {
FillBrush.SurroundColors = new Color[] {
Color.FromArgb(0, 0, 0),
Color.FromArgb(51, 51, 51),
Color.FromArgb(102, 102, 102),
Color.FromArgb(173, 173, 173)
};
FillBrush.CenterColor = Color.FromArgb(255, 255, 255);
e.Graphics.FillPath(FillBrush, Path);
}
}
}
}
Also, I've tried using FocusScales, but got no success from it either. In the example the letter "I" is shown, but this needs to work with all letters. Any help is highly appreciated.
P.S. Letter "N" as reference, sorry for the bad drawing, but this just a quick and dirty example. The letter needs to be filled with a 5 color gradient (from black at the edges to white in the middle), but taking into account the letter width. And if someone is interested, this is needed for simulating the depth dimension for the toolpath of a CNC machine.The white - middle part has the maximum depth.
The whole letter should be filled with the gradient(s), please zoom-in to get the idea.