C# GraphicsPath 添加不透明文本

C# GraphicsPath adding text with opacity

我正在使用以下代码向图像添加文本:

    private void AddText(Graphics graphics, FontDetails fontDetails, Rectangle destination)
    {
        using (GraphicsPath graphicsPath = new GraphicsPath())
        {
            graphicsPath.AddString(
                "My sample text",
                fontDetails.FontFamily,
                fontDetails.FontStyle,
                fontDetails.FontEmHeight,
                destination,
                fontDetails.FontStringFormat
            );

            graphics.FillPath(new SolidBrush(FontColour), graphicsPath);
        }
    }

一切正常。我希望能够对文本应用不透明效果,但似乎找不到执行此操作的选项。

如有任何帮助,我们将不胜感激。

我想如果你这样构造它,你可以给实心画笔添加一个不透明度值:

SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 255));
graphics.FillPath(semiTransBrush, graphicsPath);

填充形状时,必须将 Brush 对象传递给 Graphics class 的填充方法之一。 SolidBrush 构造函数的一个参数是 Color 对象。要填充不透明形状,请将颜色的 alpha 分量设置为 255。要填充半透明形状,请将 alpha 分量设置为 1 到 254 之间的任何值。

https://msdn.microsoft.com/en-us/library/5s2dwfx1(v=vs.110).aspx