C# - 从图像或图像集创建字体
标题确实说明了一切。我需要帮助从一组单独的图像文件或从一个图像创建自定义字体,该图像在 C# 中以网格方式设置了一系列字符。我到处搜索,但没有找到关于该主题的任何有用的资源。如果您有任何建议,请提前致谢。
The title really says it all. I need help in creating a custom font from either a set of separate image files or from one image with a series of characters setup in a grid fashion in C#. I have searched everywhere and haven't found any useful resources on the subject. If you have any advice, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,C# 框架中没有任何内容允许创建字体,从外观上看,您必须自己实现它。当然,微软推出了一些用于字体创建的工具和 SDK,此处以及其他信息此处 Microsoft 之外还有多种工具也可让您创建字体,例如这个。我确信这并不完全是您想要的,但这是一个开始。
As far as I have read, there is nothing within the C# framework that allows for the creation of a font, by the looks of it you will have to implement this on your own. Microsoft of course puts out some tools and a SDK for font creation, here along with other information here There are several tools outside of Microsoft that will allow you to create fonts aswell, for example this. I'm sure this isn't quite what you are looking for but it's a start.
这是 20 年前的事情,当时 TrueType 等可自由缩放的轮廓字体技术还没有出现。其中一些字体仍然在您的计算机上,即 c:\windows\fonts 中的 .fon 文件。它们实际上包含字体中字母的位图,对于字体支持的每个单独的字体高度,通常大约有 256 个位图。
.NET 中不支持这些字体,因此不要考虑创建其中一种。一般来说,不使用 TrueType 字体的缺点是:
有可用的工具来创建您的字体自己的 TrueType 字体。要做到这一点并不容易,让 TrueType 发光的原因之一是“提示”,当字体以小磅值渲染时改变字母形状,以便它们仍然清晰可辨。 Verdana 是一种典型的字体,暗示得非常好。
无论如何,为了实现您的方法,您需要创建一个位图,其中包含您愿意支持的所有字母,例如水平排列。订购它们的最佳方法是选择离您较近的代码页中的字母,例如 Windows 1252 这在西欧和美洲很常见。
如果字体是固定间距的,事情就很简单,每个字母都会以字母宽度的倍数开始。按比例间隔的字体需要一个单独的查找表来指定每个字母开始的像素偏移量。例如,使用 System.Drawing,您可以使用 Graphics.DrawImage(image,矩形,矩形,graphicsunit) 重载来设置矩形,以便复制要渲染的字母。使用 Encoding.GetBytes() 将要渲染的字符串转换为字体位图中的索引。
This was something that was done 20 years ago, before freely scalable outline font technologies like TrueType became available. Some of these fonts are still on your machine, the .fon files in c:\windows\fonts. They actually contain bitmaps of the letters in the font, usually around 256 of them for each individual font height supported by the font.
Support for these fonts is not present in .NET so don't consider creating one of them. In general, the disadvantages of not using a TrueType font are:
Tools are available to create your own TrueType font. It is not exactly easy to get right, one of the things that makes TrueType shine is 'hinting', altering the letter shapes when they font is rendered at small point sizes so that they are still legible. Verdana is a exemplary font that is hinted extraordinarily well.
Anyhoo, to pursue your approach you'll need to create a bitmap that contains all the letters that you are willing to support, arranged horizontally for example. The best way to order them is to pick the letters in a code page that's close to you, like Windows 1252 which is common in Western Europa and the Americas.
Things are simple if the font is fixed-pitched, every letter will start at a multiple of the letter width. A proportionally spaced font requires a separate lookup table that specifies at what pixel offset each letter starts. Using System.Drawing for example, you'd use the Graphics.DrawImage(image, rectangle, rectangle, graphicsunit) overload where you setup the rectangles so that the letter you want to render is copied. Use Encoding.GetBytes() to convert the string to render to indices in your font bitmap.