OK, so I'm experiencing the weirdest problem. I'm drawing some text and it's showing up corrupted:
[attachment=20278:Corrupted.png]
So, as you can see, the image on the left shows the corrupted text in Windows 8.1 and on the right the actual text is being rendered correctly in Windows 7.
The corruption only happens when I have the CompositingMode set to SourceCopy and the TextRenderingHint set to SingleBitPerPixel (with and without GridFit). I require SourceCopy as my compositing mode because I need to write to the alpha channel of the bitmap instead of blending the alpha with the bitmap contents.
The code that draws this text is incredibly simple, so I am at a loss as to why this is happening.
Anyone else run into this problem? Know of a way around it?
Here's the code that I used to repro the error:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestFontAntiAlisBug
{
public partial class Form1 : Form
{
private Bitmap _image;
private Font _font;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_font = new Font("Andalus", 48.0f, GraphicsUnit.Point);
_image = new Bitmap(256, 256, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(_image))
{
g.Clear(Color.Black);
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
using (Brush brush = new SolidBrush(Color.White))
{
g.DrawString("Are you corrupted?", _font, brush, new PointF(0, 0));
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(_image, new Point(0, 0));
}
public Form1()
{
InitializeComponent();
}
}
}