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);
}
}
// 异步调用
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);
}
}