使用“DrawString”进行小型大写/多种字体和粗体显示 在 GDI+

发布于 2024-07-14 21:51:23 字数 983 浏览 4 评论 0原文

我想使用 小型大写字母 结合不同单词的不同字体写出一些文本。

为了澄清,我可能需要消息“欢迎来到我们的新网站”,该消息生成为 PNG 文件作为页面标题。

  • 文本将是 smallcaps - 除“W”、“N”和“以外的所有内容均大写” W'稍大一些。
  • “新网站”的字体将与文本的其余部分不同。

有没有一种方法可以让我无需完全手动完成此操作?

从概念上讲,做这样的事情是我想做的:

 graphics.DrawString("<font size=2>W</font>ELCOME TO OUR <b><font size=2>N</font>" +
                     "EW <font size=2>W</font>EBSITE</b>");

迄今为止我能找到的最佳方法 在这里,但我担心我会费尽心思手动执行此操作,最终会得到一些可怕的字距调整或跟踪问题。

编辑:我应该提到,这是在 ASP.NET 中完成的,因此它需要快速且尽可能精简。 我希望它是自动化的,这样我就可以轻松本地化,而不必创建大量的小图像。

I want to write out some text using smallcaps in combination with different fonts for different words.

To clarify I might want the message 'Welcome to our New Website' which is generated into a PNG file for the header of a page.

  • The text will be smallcaps - everything is capitalized but the 'W', 'N' and 'W' are slightly larger.
  • The 'New Website' will be in a different font than the rest of the text.

Is there a way i can do this without doing it completely manually?

Doing something like this is conceptually what I want to do :

 graphics.DrawString("<font size=2>W</font>ELCOME TO OUR <b><font size=2>N</font>" +
                     "EW <font size=2>W</font>EBSITE</b>");

The best approach I could find so far is here, but I'm worried that I'll go to all the trouble to do this manually and end up with some horrible kerning or tracking problems.

Edit: I should have mentioned that this is being done within ASP.NET so it needs to be fast and as lean as possible. I want it to be automated so I can localize easily and not have to create tonnes of little images.

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

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

发布评论

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

评论(1

捂风挽笑 2024-07-21 21:51:23

看来您确实应该在这里使用 RichTextBox...有一种方法可以从 RichTextBox 中提取位图,然后您可以将其渲染为图形上下文的位图。 当然,您需要在此处进行托管 C++ 调用,我不知道您是否能够在您的项目中执行此操作。

否则,我认为您将需要使用 DrawString 和 MeasureString 手动完成,这很痛苦。

It seems like you should really be using a RichTextBox here... there is a method to extract a bitmap from the RichTextBox which you could then render as a bitmap to your graphics context. Of course, you'd need to make a Managed C++ call here and I don't know if you're able to do that in your project.

Otherwise, I think you will need to do it manually with DrawString and MeasureString, which is a pain.

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