使用GDI+使用 C# 为网站创建图像
我想使用 GDI 在服务器上生成带有我的字体的文本图像,以便在我的网站上提供服务。
我想在我的网站上使用任何字体,但当然不能在网站上使用任何字体......所以我想我需要自己生成文本的图像。
想法如何实现这一目标?
谢谢。
I'd like to use GDI to generate text images with my fonts on a server to be served on my site.
I want to use any font on my sites, but of course couldn't use any font on a web site... so I guess I'd need to generate images of the text myself.
Ideas how to accomplish this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将简单地创建一个带有一定大小的文本的图像并将其分配给图片框。您当然需要添加用于设置对齐和类似性质的功能,但这是基本思想。创建一个图像,从中获取一个 Graphics 对象,然后绘制一个字符串。
您还可以使用 Graphics.MeasureString 方法获取使用某种字体“f”绘制的字符串的宽度和高度。
That will simply create an image with some text of a certain size and assign it to a picturebox. You would of course need to add functionality for setting alignment and things of that nature, but this is the basic idea. Create an image, get a Graphics object from it, and draw a string.
You can also obtain the width and height of a drawn string using some font 'f' by using the Graphics.MeasureString method.
为了清晰起见,采用硬编码的代码示例:
图片大小 (200x100)、文本、字体、起始位置 (0,0) 和目标路径都是硬编码的。
Code sample with hard-coding for clarity:
The picture size (200x100), text, font and starting location (0,0) and destination path are all hard-coded.