✅ weird transparent areas when using GraphicsPath to draw a string
Bitmap realText = new(width, height);
using GraphicsPath segments = new();
using (var textGraphics = Graphics.FromImage(realText))
{
textGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
textGraphics.SmoothingMode = SmoothingMode.AntiAlias;
textGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
textGraphics.CompositingQuality = CompositingQuality.HighQuality;
if (description.Debug)
{
FastRandom r = new(cache.Count);
textGraphics.Clear(Color.FromArgb(r.Next(100, 255), r.Next(100, 255), r.Next(100, 255)));
}
segments.AddString(text, font.FontFamily, (int)description.FontStyle, graphics.DpiY * font.SizeInPoints / 72, new PointF(x, y), format);
segments.CloseAllFigures();
for (var i = 0; i < effects.Length; ++i) if (!effects[i].Overlay) effects[i].Draw(realText, textGraphics, segments, x, y);
if (!description.EffectsOnly) using (SolidBrush brush = new(description.Color)) textGraphics.FillPath(brush, segments);
for (var i = 0; i < effects.Length; ++i) if (effects[i].Overlay) effects[i].Draw(realText, textGraphics, segments, x, y);
if (description.Debug) using (Pen pen = new(Color.Red))
{
textGraphics.DrawLine(pen, x, y, x, y + baseHeight);
textGraphics.DrawLine(pen, x - baseWidth * .5f, y, x + baseWidth * .5f, y);
}
}
Bitmap realText = new(width, height);
using GraphicsPath segments = new();
using (var textGraphics = Graphics.FromImage(realText))
{
textGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
textGraphics.SmoothingMode = SmoothingMode.AntiAlias;
textGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
textGraphics.CompositingQuality = CompositingQuality.HighQuality;
if (description.Debug)
{
FastRandom r = new(cache.Count);
textGraphics.Clear(Color.FromArgb(r.Next(100, 255), r.Next(100, 255), r.Next(100, 255)));
}
segments.AddString(text, font.FontFamily, (int)description.FontStyle, graphics.DpiY * font.SizeInPoints / 72, new PointF(x, y), format);
segments.CloseAllFigures();
for (var i = 0; i < effects.Length; ++i) if (!effects[i].Overlay) effects[i].Draw(realText, textGraphics, segments, x, y);
if (!description.EffectsOnly) using (SolidBrush brush = new(description.Color)) textGraphics.FillPath(brush, segments);
for (var i = 0; i < effects.Length; ++i) if (effects[i].Overlay) effects[i].Draw(realText, textGraphics, segments, x, y);
if (description.Debug) using (Pen pen = new(Color.Red))
{
textGraphics.DrawLine(pen, x, y, x, y + baseHeight);
textGraphics.DrawLine(pen, x - baseWidth * .5f, y, x + baseWidth * .5f, y);
}
}
1 Reply
never mind, I found out that you need to change the GraphicsPath fill mode to winding