When alpha blending some greyscale images on Win7 x64 I m getting strange tearing and flicker. It s fine on XP & Vista (both x64 and x86) and Win7 x86. I ve tried it on several Win7 machines, and they all show the problem.
The code that shows up the problem is:
public partial class Form1 : Form
{
Image image;
float alpha = 0;
float delta = 0.1f;
Timer timer;
public Form1()
{
InitializeComponent();
DoubleBuffered = true;
Paint += Form1_Paint;
image = Image.FromFile(@"image.jpg");
timer = new Timer {Interval = 50};
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
if (alpha > 1 || alpha < 0)
{
delta = -delta;
}
alpha += delta;
Invalidate();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.White, new Rectangle(0, 0, image.Width, image.Height));
float[][] matrix = {
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, alpha, 0},
new float[] {0, 0, 0, 0, 1}
};
var colorMatrix = new ColorMatrix(matrix);
using (var attributes = new ImageAttributes())
{
attributes.SetColorMatrix(colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
e.Graphics.DrawImage(image,
new Rectangle(0, 0, image.Width, image.Height),
0, 0, image.Width, image.Height,
GraphicsUnit.Pixel, attributes);
}
}
}
(this is part of default Windows Form project)
The image that shows the problem is:
Am I doing something wrong with my ColorMatrix code? Or is this one of those rare cases where I may have found a problem in the Framework/OS/whatever I m building on top of?