6

TextRenderer(これは を使用するのに適しているためGraphics.DrawString) を使用してテキストを描画しようとしていますBitmapが、非常に望ましくない効果がいくつかあります。

サンプルコード

using (Bitmap buffer = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
    using (Graphics graphics = Graphics.FromImage(buffer))
    {
        // Produces the result below
        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
        // Produces clean text, but I'd really like ClearType!
        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        TextRenderer.DrawText(graphics, "Hello World", this.Font, this.ClientRectangle, Color.Black);
    }
    e.Graphics.DrawImageUnscaled(buffer, this.ClientRectangle);
}

結果

ここに画像の説明を入力

これを修正する方法が正確にはわかりません...助けてください!

Graphics.DrawString正しい GDI (GDI+ ではなく) レンダリングが必要なため、使用したくありません。

注:この質問に大きな穴を残してしまったことに気付きました。一部の人々は、ClearType テキストのレンダリングが自分のマシンで正常に機能していると指摘しています...

テキストを透明 (Color.Transparent) ビットマップにレンダリングしようとしています。単色でやると上手くいきます!(ただし、透明なビットマップにレンダリングすることが不可欠です)。

4

3 に答える 3

4

あなたの設定を試すことができTextRenderingHintますImage Graphics

using (Graphics graphics = Graphics.FromImage(buffer))
{
    graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
    TextRenderer.DrawText(graphics, "Hello World", this.Font, this.ClientRectangle, Color.Black);
}
于 2013-09-17T02:36:29.213 に答える
4

DrawText() への呼び出しで BackColor を指定します。

TextRenderer.DrawText(graphics, "Hello World", this.Font, this.ClientRectangle, Color.Black, this.BackColor);
于 2013-09-16T23:28:10.187 に答える