【问题标题】:C# GraphicsPath adding text with opacityC# GraphicsPath 添加不透明的文本
【发布时间】:2016-06-17 03:07:05
【问题描述】:

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

    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);
        }
    }

这是完美的工作。我希望能够对文本应用不透明效果,但似乎找不到执行此操作的选项。

任何帮助将不胜感激。

【问题讨论】:

  • 使用 alpha,例如 FontColour = Color.FromArgb(32, Color.Black);扔掉画笔。

标签: c# text opacity graphicspath


【解决方案1】:

如果你像这样构造它,我认为你可以为实体画笔添加一个不透明度值:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 2011-01-25
    相关资源
    最近更新 更多