方法自身实现异部调用和WinForm上图片切换效果
2009-03-16 16:28
681 查看
以下的代码图片的切换效果已经出来了,但是奇慢无比,本来打算在循环内部加入"Thread.Sleep(n);",但是不用加也很慢。看来C#实现漂亮的图片切换效果我是不行了,希望那位前辈给帮一下忙。
private void SwitchImage(PictureBox pb,Image img,bool isAsync) {
//异步调用
if (isAsync) {
Thread t = new Thread(delegate(object o) {
SwitchImage((PictureBox)(((System.Collections.Stack)o).Pop()),
(Image)(((System.Collections.Stack)o).Pop()),
(bool)(((System.Collections.Stack)o).Pop())
);
});
System.Collections.Stack st = new System.Collections.Stack(3);
st.Push(false);
st.Push(img);
st.Push(pb);
t.Start(st);
return;
}
float opacity = 0;
float[][] nArray ={ 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, opacity, 0},
new float[] {0, 0, 0, 0, 1}
};
while (opacity < 1){
opacity += 0.1F;
nArray[3][3] = opacity;
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap resultImage = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
pb.Image = resultImage;
//Thread.Sleep(100);
}
}
private void SwitchImage(PictureBox pb,Image img,bool isAsync) {
//异步调用
if (isAsync) {
Thread t = new Thread(delegate(object o) {
SwitchImage((PictureBox)(((System.Collections.Stack)o).Pop()),
(Image)(((System.Collections.Stack)o).Pop()),
(bool)(((System.Collections.Stack)o).Pop())
);
});
System.Collections.Stack st = new System.Collections.Stack(3);
st.Push(false);
st.Push(img);
st.Push(pb);
t.Start(st);
return;
}
float opacity = 0;
float[][] nArray ={ 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, opacity, 0},
new float[] {0, 0, 0, 0, 1}
};
while (opacity < 1){
opacity += 0.1F;
nArray[3][3] = opacity;
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap resultImage = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attributes);
pb.Image = resultImage;
//Thread.Sleep(100);
}
}
相关文章推荐
- js实现同一页面可多次调用的图片幻灯切换效果
- JS+CSS实现自动改变切换方向图片幻灯切换效果的方法
- Winform下实现图片切换特效的方法
- JS+CSS实现自动改变切换方向图片幻灯切换效果的方法
- jquery简单实现图片切换效果的方法
- jquery实现两个图片渐变切换效果的方法
- 【jQuery】调用toggle()方法实现动画切换效果
- JS实现FLASH幻灯片图片切换效果的方法
- js实现图片从左往右渐变切换效果的方法
- js仿土豆网带缩略图的焦点图片切换效果实现方法
- jquery简单实现图片切换效果的方法
- JS实现FLASH幻灯片图片切换效果的方法
- jquery实现焦点图片随机切换效果的方法
- jquery简单图片切换显示效果实现方法
- 淘宝首页 图片滑动切换效果 基于jQuery的animate方法实现
- js仿土豆网带缩略图的焦点图片切换效果实现方法
- 利用jquery的attr方法一行代码实现的简单的图片切换效果
- JS+CSS实现淡入式焦点图片幻灯切换效果的方法
- js实现同一页面可多次调用的图片幻灯切换效果
- js实现图片从左往右渐变切换效果的方法