Graphics.DrawString指定文本的不透明度

发布于 2024-11-19 02:21:13 字数 299 浏览 6 评论 0原文

是否可以指定使用 Graphics.DrawString 方法编写的文本的不透明度?

我正在做类似的事情,但如果可能的话,希望我的文本是半透明的。

目前我正在这样做:

Graphics graphics = Graphics.FromImage(image);
graphics.DrawString("This is a watermark", 
    new Font("Arial", 40), 
    new SolidBrush(Color.Red), 
    0, 
    0);

Is it possible to specify the opacity of text written using the Graphics.DrawString method?

I'm doing something like this, but would like my text to be semi-transparent if it is possible.

Currently I'm doing this:

Graphics graphics = Graphics.FromImage(image);
graphics.DrawString("This is a watermark", 
    new Font("Arial", 40), 
    new SolidBrush(Color.Red), 
    0, 
    0);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

棒棒糖 2024-11-26 02:21:14

尝试:

int opacity = 128; // 50% opaque (0 = invisible, 255 = fully opaque)
using (var graphics = Graphics.FromImage(image))
using (var font = new Font("Arial", 40))
using (var brush = new SolidBrush(Color.FromArgb(opacity, Color.Red)))
    graphics.DrawString("This is a watermark", font, brush, 0, 0);

Try:

int opacity = 128; // 50% opaque (0 = invisible, 255 = fully opaque)
using (var graphics = Graphics.FromImage(image))
using (var font = new Font("Arial", 40))
using (var brush = new SolidBrush(Color.FromArgb(opacity, Color.Red)))
    graphics.DrawString("This is a watermark", font, brush, 0, 0);
谎言 2024-11-26 02:21:14

尝试

new SolidBrush(Color.FromArgb(0x78FF0000))

希望这有帮助

Try

new SolidBrush(Color.FromArgb(0x78FF0000))

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文