在透明像素顶部使用DrawString进行错误文本渲染 [英] Bad text rendering using DrawString on top of transparent pixels

查看:77
本文介绍了在透明像素顶部使用DrawString进行错误文本渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将文本渲染到位图中时,我发现当在具有非透明alpha区域的顶部渲染文本时,文本看起来非常糟糕.随着下面的像素变得更加透明,问题变得越来越严重.如果我不得不猜测,我会说当基础像素是透明的时,文本渲染器会将所有抗锯齿的灰色"像素绘制为纯黑色.

When rendering text into a bitmap, I find that text looks very bad when rendered on top of an area with non-opaque alpha. The problem is progressively worse as the underlying pixels become more transparent. If I had to guess I'd say that when underlying pixels are transparent, the text renderer draws any anti-aliased 'gray' pixels as solid black.

以下是一些屏幕截图:

在透明像素上方绘制的文本:

在半透明像素上方绘制的文本:

在不透明像素上绘制的文本:

以下是用于呈现文本的代码:

Here is the code used to render the text:

g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawString("Press the spacebar", Font, Brushes.Black, textLeft, textTop);

推荐答案

我用来解决此问题的选项是:

The option I used to workaround this problem was:

Graphics graphics = new Graphics();
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

TextRenderingHint中还有一些其他有用的选项

There are some others useful options in TextRenderingHint

希望有帮助

这篇关于在透明像素顶部使用DrawString进行错误文本渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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