在Win7 x64上使用.NET中的ImageAttributes ColorMatrix时出现奇怪的闪烁
当alpha在win7x64上混合一些灰度图像时,我感到奇怪的撕裂和闪烁。在XP&Vista(x64和x86)和Win7 x86上都可以。我已经在几台Win7机器上试过了,它们都显示了这个问题 显示问题的代码是:在Win7 x64上使用.NET中的ImageAttributes ColorMatrix时出现奇怪的闪烁,.net,drawing,.net,Drawing,当alpha在win7x64上混合一些灰度图像时,我感到奇怪的撕裂和闪烁。在XP&Vista(x64和x86)和Win7 x86上都可以。我已经在几台Win7机器上试过了,它们都显示了这个问题 显示问题的代码是: public partial class Form1 : Form { Image image; float alpha = 0; float delta = 0.1f; Timer timer; public Form1() {
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);
}
}
}
公共部分类表单1:表单
{
图像;
浮点α=0;
浮动增量=0.1f;
定时器;
公共表格1()
{
初始化组件();
双缓冲=真;
油漆+=Form1_油漆;
image=image.FromFile(@“image.jpg”);
定时器=新定时器{Interval=50};
timer.Tick+=定时器_Tick;
timer.Start();
}
无效计时器勾号(对象发送方,事件参数e)
{
如果(alpha>1 | | alpha<0)
{
delta=-delta;
}
α+=δ;
使无效();
}
私有void Form1_Paint(对象发送器、PaintEventArgs e)
{
e、 Graphics.FillRectangle(笔刷.White,新矩形(0,0,image.Width,image.Height));
浮点[][]矩阵={
新浮点[]{1,0,0,0,0},
新浮点[]{0,1,0,0,0},
新浮点[]{0,0,1,0,0},
新浮点[]{0,0,0,alpha,0},
新浮点[]{0,0,0,0,1}
};
var colorMatrix=新的colorMatrix(矩阵);
使用(var attributes=newimageattributes())
{
属性。SetColorMatrix(colorMatrix,
ColorMatrixFlag.Default,
颜色调整类型(位图);
e、 图形。DrawImage(图像,
新矩形(0,0,image.Width,image.Height),
0,0,图像。宽度,图像。高度,
GraphicsUnit.Pixel,属性);
}
}
}
(这是默认Windows窗体项目的一部分)
显示问题的图像是:
我的ColorMatrix代码有问题吗?或者这是我在框架/操作系统/我正在构建的任何东西中发现问题的罕见案例之一