低级 C - 逐像素显示文本 [英] Low level C - Display text, pixel by pixel

查看:40
本文介绍了低级 C - 逐像素显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目,我必须在其中编写一个低级应用程序.我想在该应用程序中显示文本,我什至希望它具有抗锯齿功能(à la ClearType).不允许使用库,我必须逐个像素地绘制每个字符.

I am working on a small project where I have to write a low level app. I'd like to display text in that app, and I would even like it to be anti aliased (à la ClearType). No libraries allowed, I have to draw each char pixel by pixel.

这样做的最佳方法是什么?你能推荐一些已知的算法吗?我应该如何存储/读取字体?

What is the best way to do this? Can you recommend some known algorithms? How should I store/read the fonts?

谢谢!

推荐答案

您是说只想平滑现有位图字体的边缘?如果您的原始字体是 16x32 并且您想以 8x16 或类似的格式渲染它,这很容易,但是如果您没有更高分辨率的位图开始,平滑是一个非常重要的操作,涉及很多猜测.在这种情况下,我会查找 2xsai 算法(它为此类事情提供视觉上令人愉悦的结果)并首先执行它以将字体放大到双倍分辨率,然后将其缩小到一个区域- 平均算法(即从 4 像素正方形的平均值中取出每个目标像素).

You mean you just want to smooth the edges of an existing bitmapped font? This is easy if your original font is 16x32 and you want to render it at 8x16 or something like that, but if you don't have a higher-resolution bitmap to begin with, smoothing is a highly nontrivial operation involving a lot of guesswork. In that case, I would lookup the 2xsai algorithm (which gives visually-pleasing results for this kind of thing) and first perform it to upscale the font to double resolution, then scale it back down with a area-averaging algorithm (i.e. take each destination pixel from the average of a 4-pixel square).

我还建议您保存最终的抗锯齿"位图字体并在您的程序中简单地使用它,而不是在运行时执行所有这些工作.

I would also recommend saving your final "anti-aliased" bitmap font and simply using it in your program, rather than performing all this work at runtime.

这篇关于低级 C - 逐像素显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆