方法自身实现异部调用和WinForm上图片切换效果

以下的代码图片的切换效果已经出来了,但是奇慢无比,本来打算在循环内部加入"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);
            }
        }

转载于:https://www.cnblogs.com/gleamy_ming/archive/2009/03/16/1413347.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值