【发布时间】:2014-08-21 18:49:16
【问题描述】:
我写了一个脚本,在 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 中得到难看的伪影,如下图所示。
如何避免它们?
桑德罗
【问题讨论】:
-
这完全有道理,就像一个魅力!如果您将其发布为答案,我很高兴为您提供信誉:-)