我编写了一个脚本,它将文本呈现为Powershell中的图像。
这些应该是相关的代码片段:
$fontFamily = new-object System.Drawing.FontFamily "Arial"
$stringFormat = new-object System.Drawing.StringFormat
$fontSize = 50
# background brush, transparent
$brushBg = [System.Drawing.Brushes]::Black
# foreground brush
$colorFg = [System.Drawing.Color]::FromArgb(105, 160, 215)
$colorOutline = [System.Drawing.Color]::FromArgb(255, 255, 255)
$brushFg = new-object System.Drawing.SolidBrush($colorFg)
$path = new-object System.Drawing.Drawing2D.GraphicsPath
$path.AddString("sometext", $fontFamily, [int]([System.Windows.FontStyle]::Regular), ([float] $fontSize), (new-object System.Drawing.Point 0, 0), $stringFormat)
# ...
# magically get some graphics context to draw on
# ....
# draw the outline in white
$pen = new-object System.Drawing.Pen($colorOutline, 12)
$graphics.DrawPath($pen, $path)
$pen.Dispose()
# draw the text itself in blue
$graphics.FillPath($brushFg, $path)
...
现在问题是当我使轮廓太宽时,我从DrawPath中得到了丑陋的文物,如下图所示。
如何避免它们?
桑德罗
答案 0 :(得分:1)
这些尖峰是由W形状的急剧过渡引起的。笔的MitreLimit的副作用。更改Pen.LineJoin属性通常是最好的,您可以通过选择斜角或圆形来消除这些斜接工件。