TextRenderer.DrawText in Bitmap vs OnPaintBackground

前端 未结 6 992
无人共我
无人共我 2020-12-18 03:01

If I use TextRenderer.DrawText() using the Graphics object provided in the OnPaintBackground my text looks perfect. If I create my own

6条回答
  •  情深已故
    2020-12-18 03:59

    Can you post the smallest program that suffers from this problem? I can't reproduce it like this -- the antialiasing looks fine:

        using System.Drawing;
    using System.Drawing.Imaging;
    using System.Windows.Forms;
    
    public class Program
    {
        public static void Main()
        {
            Bitmap bmp = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
            using (Font font = new Font("Arial", 10, GraphicsUnit.Point))
            using (Graphics g = Graphics.FromImage(bmp))
            {
                Rectangle clip = Rectangle.FromLTRB(0, 0, 100, 100);
                g.Clear(Color.Red);
                TextFormatFlags tf = TextFormatFlags.Left;
                TextRenderer.DrawText(g, @"C:\Development\Testing\blag", font, clip, Color.White, Color.Transparent, tf);
            }
    
            Form form = new Form();
            form.BackgroundImage = bmp;
            Application.Run(form);
        }
    }
    

提交回复
热议问题