.
In Depth Banner
Skip Navigation Links

Select your preferred language

Drawing the transitions.

        //The fade transition is presented for completeness

        case TransitionTypes.Fade:

        {

          //This transition fades one image over the other

          ImageAttributes ia=new ImageAttributes();

          ColorMatrix cm=new ColorMatrix();

          cm.Matrix33=1f/255*(255*_currentPercentage/100);

          ia.SetColorMatrix(cm);

          e.Graphics.DrawImage(_imageB,this.ClientRectangle,0,0,_imageB.Width,_imageB.Height,GraphicsUnit.Pixel,ia);

          ia.Dispose();

        }

          break;

/////////////////////////////////////////////////////////////////////////////////

        case TransitionTypes.Iris:

          // use a path

          pth=new GraphicsPath();

          // calculate the width and height of the ellipse

          int w=(int)((this.Width*1.414f)*_currentPercentage/200);

          int h=(int)((this.Height*1.414f)*_currentPercentage/200);

          pth.AddEllipse(

            this.Width/2-w,

            this.Height/2-h,

            2*w,

            2*h

            );

          // set the clipping region

          e.Graphics.SetClip(pth,CombineMode.Replace);

          //paint the image

          e.Graphics.DrawImage(_imageB,

            ClientRectangle,

            0,0,_imageB.Width,_imageB.Height,

            GraphicsUnit.Pixel);

          pth.Dispose();

          break;

/////////////////////////////////////////////////////////////////////////////////

        case TransitionTypes.Slide:

          // a matrix is used to set the offset of the image

          Matrix mx=new Matrix(1,0,0,1,(this.Width*_currentPercentage/100)-this.Width,0);

          // the matrix modifies the Graphics object

          e.Graphics.Transform=mx;

          // the image is drawn

          e.Graphics.DrawImage(_imageB,

            ClientRectangle,

            0,0,_imageB.Width,_imageB.Height,

            GraphicsUnit.Pixel);

          break;

/////////////////////////////////////////////////////////////////////////////////

        case TransitionTypes.Spin:

          // calculate the degrees of spin

          float degrees=360*_currentPercentage/100;

          //and the origin (center of the client area

          float ofsX=this.Width/2;

          float ofsY=this.Height/2;

          //calculate the scale at which the image will be drawn

          float Scale=1*_currentPercentage/100;

          //catering for zero's which will cause an exception

          if(Scale==0)

            Scale=0.0001f;

          //create a matrix with the scale and origin

          Matrix rm=new Matrix(Scale,0,0,Scale,ofsX,ofsY);

          //do the spin

          rm.Rotate(degrees,MatrixOrder.Prepend);

          //use the matrix

          e.Graphics.Transform=rm;

          //draw the image

          e.Graphics.DrawImage(_imageB,new Rectangle(-Width/2, -Height/2, Width, Height),0,0,_imageB.Width,_imageB.Height,GraphicsUnit.Pixel);

          rm.Dispose();

          break;

/////////////////////////////////////////////////////////////////////////////////

        case TransitionTypes.Blinds:

          // blinds divide the image into n horizontal stripes

          for(int y=0; y<_nHDivs; y++)

          {

            //for each stripe, find the source in the overlay image

            Rectangle src=new Rectangle(0,y*(_imageB.Height/_nHDivs),_imageB.Width,_imageB.Height/_nHDivs);

            //calculate the destination

            Rectangle drc=new Rectangle(0,y*(Height/_nHDivs),Width,(int)((Height/_nHDivs)*_currentPercentage/100));

            drc.Offset(0,(Height/(_nHDivs*2))-drc.Height/2);

            //draw the slice

            e.Graphics.DrawImage(_imageB,drc,src,GraphicsUnit.Pixel);

          }

          break;

 

Return to the article

Copyright © Bob Powell 2000-.  All rights reserved.