这是截屏动画效果:
这次是(中),共10种特效:
- #region 随机竖条
-
-
- private void Animator11()
- {
- const float lineWidth = 40;
- const int stepCount = 12;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- Random rnd = new Random();
-
- int[] colIndex = new int[(int)Math.Ceiling(bmp.Width / lineWidth)];
- int index = 1;
-
-
- do
- {
- int s = rnd.Next(colIndex.Length);
- if (colIndex[s] == 0)
- {
- colIndex[s] = index++;
- }
- } while (index <= colIndex.Length);
-
- for (int i = 0; i < colIndex.Length; i++)
- {
- for (int y = 0; y < bmp.Height; y += stepCount)
- {
- RectangleF rect = new RectangleF((colIndex[i] - 1) * lineWidth, y, lineWidth, stepCount);
- dc.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);
-
- Thread.Sleep(1 * delay);
- ShowBmp(rect);
- }
-
- Thread.Sleep(10 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 随机拉丝
-
-
- private void Animator12()
- {
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- Random rnd = new Random();
-
- int[] rowIndex = new int[bmp.Height];
- int index = 1;
- do
- {
- int s = rnd.Next(rowIndex.Length);
- if (rowIndex[s] == 0)
- {
- rowIndex[s] = index++;
- }
- } while (index <= rowIndex.Length);
-
- for (int i = 0; i < rowIndex.Length; i++)
- {
- RectangleF rect = new RectangleF(0, (rowIndex[i] - 1), bmp.Width, 1);
- dc.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);
-
- ShowBmp(rect);
- Thread.Sleep(1 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 垂直对切
-
-
- private void Animator13()
- {
- const int stepCount = 4;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
-
- for (int y = 0; y <= bmp.Height / 2; y += stepCount)
- {
-
- Rectangle rectLeft = new Rectangle(0, bmp.Height / 2 - y - stepCount, bmp.Width / 2, stepCount);
- dc.DrawImage(bmp, rectLeft, rectLeft, GraphicsUnit.Pixel);
-
- Rectangle rectRight = new Rectangle(bmp.Width / 2, bmp.Height / 2 + y, bmp.Width / 2, stepCount);
- dc.DrawImage(bmp, rectRight, rectRight, GraphicsUnit.Pixel);
-
- ShowBmp(Rectangle.Union(rectLeft, rectRight));
- Thread.Sleep(10 * delay);
- }
-
- for (int y = 0; y <= bmp.Height / 2; y += stepCount)
- {
-
- Rectangle rectLeft = new Rectangle(0, bmp.Height - y - stepCount, bmp.Width / 2, stepCount);
- dc.DrawImage(bmp, rectLeft, rectLeft, GraphicsUnit.Pixel);
-
- Rectangle rectRight = new Rectangle(bmp.Width / 2, y, bmp.Width / 2, stepCount);
- dc.DrawImage(bmp, rectRight, rectRight, GraphicsUnit.Pixel);
-
- ShowBmp(Rectangle.Union(rectLeft, rectRight));
- Thread.Sleep(10 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 随机分块
-
-
- private void Animator14()
- {
- const float blockSize = 50;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- Random rnd = new Random();
-
- int[,] blockIndex = new int[(int)Math.Ceiling(bmp.Width / blockSize), (int)Math.Ceiling(bmp.Height / blockSize)];
-
-
- int s = 1;
- do
- {
- int x = rnd.Next(blockIndex.GetLength(0));
- int y = rnd.Next(blockIndex.GetLength(1));
- if (blockIndex[x, y] == 0)
- {
- blockIndex[x, y] = s++;
- }
- } while (s <= blockIndex.GetLength(0) * blockIndex.GetLength(1));
-
-
- for (int x = 0; x < blockIndex.GetLength(0); x++)
- {
- for (int y = 0; y < blockIndex.GetLength(1); y++)
- {
-
- RectangleF rect = new RectangleF(((blockIndex[x, y] - 1) % blockIndex.GetLength(0)) * blockSize,
- ((blockIndex[x, y] - 1) / blockIndex.GetLength(0)) * blockSize, blockSize, blockSize);
- dc.DrawImage(bmp, rect, rect, GraphicsUnit.Pixel);
-
- ShowBmp(rect);
- Thread.Sleep(10 * delay);
- }
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 对角闭幕
-
-
- private void Animator15()
- {
- const int stepCount = 4;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
-
-
-
- PointF p0 = new Point(0, 0);
- PointF p1 = new Point(0, 0);
- PointF p2 = new Point(bmp.Width - 1, bmp.Height - 1);
- PointF p3 = new Point(bmp.Width - 1, bmp.Height - 1);
-
- GraphicsPath path = new GraphicsPath();
-
- for (int y = 0; y < bmp.Height; y += stepCount)
- {
- p0.X = y * Convert.ToSingle(bmp.Width) / Convert.ToSingle(bmp.Height);
- p1.Y = y;
- p2.X = bmp.Width - 1 - p0.X;
- p3.Y = bmp.Height - 1 - p1.Y;
- path.Reset();
- path.AddPolygon(new PointF[] { p0, new PointF(bmp.Width, 0), p3, p2, new PointF(0, bmp.Height), p1 });
- dc.DrawImage(bmp, 0, 0);
- dc.FillPath(new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)), path);
-
- ShowBmp(path.GetBounds());
- Thread.Sleep(10 * delay);
- }
-
- dc.DrawImage(bmp, 0, 0);
-
- ShowBmp();
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 垂直百叶(改进版)
-
-
- private void Animator16()
- {
- const float lineHeight = 50;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- GraphicsPath path = new GraphicsPath();
- TextureBrush textureBrush = new TextureBrush(bmp);
- for (int i = 0; i < lineHeight; i++)
- {
- for (int j = 0; j < Math.Ceiling(bmp.Height / lineHeight); j++)
- {
- RectangleF rect = new RectangleF(0, lineHeight * j + i, bmp.Width, 1);
- path.AddRectangle(rect);
- }
- dc.FillPath(textureBrush, path);
-
- ShowBmp();
- Thread.Sleep(10 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 压缩竖条(改进版)
-
-
- private void Animator17()
- {
- const float lineWidth = 100;
- const int stepCount = 4;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- for (int i = 0; i < Math.Ceiling(bmp.Width / lineWidth); i++)
- {
- for (int j = stepCount; j <= lineWidth; j += stepCount)
- {
- RectangleF sourRect = new RectangleF(lineWidth * i, 0, lineWidth, bmp.Height);
- RectangleF destRect = new RectangleF(lineWidth * i, 0, j, bmp.Height);
- dc.DrawImage(bmp, destRect, sourRect, GraphicsUnit.Pixel);
-
- ShowBmp(destRect);
- Thread.Sleep(10 * delay);
- }
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 水平拉入(改进版)
-
-
-
- private void Animator18()
- {
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
-
-
- for (float i = 1; i <= dc.DpiX; i++)
- {
- RectangleF destRect = new RectangleF(0, 0, bmp.Width * dc.DpiX / i, bmp.Height);
- RectangleF sourRect = new RectangleF(0, 0, bmp.Width, bmp.Height);
- dc.DrawImage(bmp, destRect, sourRect, GraphicsUnit.Pixel);
-
- ShowBmp();
- Thread.Sleep(10 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 三色对接(改进版)
-
-
- private void Animator19()
- {
- const int stepCount = 4;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
-
- Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
-
- ColorMatrix matrix = new ColorMatrix();
- matrix.Matrix00 = 1f;
- matrix.Matrix11 = 0f;
- matrix.Matrix22 = 0f;
- ImageAttributes attributes = new ImageAttributes();
- attributes.SetColorMatrix(matrix);
- Bitmap redBmp = new Bitmap(bmp.Width, bmp.Height);
- Graphics.FromImage(redBmp).DrawImage(bmp, rect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes);
-
- matrix.Matrix00 = 0f;
- matrix.Matrix11 = 0f;
- matrix.Matrix22 = 1f;
- attributes.SetColorMatrix(matrix);
- Bitmap blueBmp = new Bitmap(bmp.Width, bmp.Height);
- Graphics.FromImage(blueBmp).DrawImage(bmp, rect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes);
-
- matrix.Matrix00 = 1f;
- matrix.Matrix11 = 0f;
- matrix.Matrix22 = 1f;
- attributes.SetColorMatrix(matrix);
- Bitmap redBlueBmp = new Bitmap(bmp.Width, bmp.Height);
- Graphics.FromImage(redBlueBmp).DrawImage(bmp, rect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes);
-
- matrix.Matrix00 = 1f;
- matrix.Matrix11 = 1f;
- matrix.Matrix22 = 0f;
- attributes.SetColorMatrix(matrix);
- Bitmap redGreenBmp = new Bitmap(bmp.Width, bmp.Height);
- Graphics.FromImage(redGreenBmp).DrawImage(bmp, rect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes);
-
- matrix.Matrix00 = 0f;
- matrix.Matrix11 = 1f;
- matrix.Matrix22 = 1f;
- attributes.SetColorMatrix(matrix);
- Bitmap blueGreenBmp = new Bitmap(bmp.Width, bmp.Height);
- Graphics.FromImage(blueGreenBmp).DrawImage(bmp, rect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes);
-
-
-
- for (int x = 0; x < bmp.Width / 2; x += stepCount)
- {
- Rectangle rectR = new Rectangle(x, 0, stepCount, bmp.Height);
- dc.DrawImage(redBmp, rectR, rectR, GraphicsUnit.Pixel);
-
- Rectangle rectB = new Rectangle(bmp.Width - x - stepCount, 0, stepCount, bmp.Height);
- dc.DrawImage(blueBmp, rectB, rectB, GraphicsUnit.Pixel);
-
- ShowBmp(Rectangle.Union(rectR, rectB));
- Thread.Sleep(10 * delay);
- }
-
-
- ColorMatrix matrixGLeft = new ColorMatrix();
- ColorMatrix matrixGRight = new ColorMatrix();
- for (int x = 0; x < bmp.Width / 4; x += stepCount)
- {
- Rectangle rectBR = new Rectangle(bmp.Width / 2 - x - stepCount, 0, 2 * (x + stepCount), bmp.Height);
- dc.DrawImage(redBlueBmp, rectBR, rectBR, GraphicsUnit.Pixel);
-
- Rectangle rectGLeft = new Rectangle(x, 0, stepCount, bmp.Height);
- dc.DrawImage(redGreenBmp, rectGLeft, rectGLeft, GraphicsUnit.Pixel);
-
- Rectangle rectGRight = new Rectangle(bmp.Width - x - stepCount, 0, stepCount, bmp.Height);
- dc.DrawImage(blueGreenBmp, rectGRight, rectGRight, GraphicsUnit.Pixel);
-
- ShowBmp(Rectangle.Union(Rectangle.Union(rectBR, rectGLeft), rectGRight));
- Thread.Sleep(10 * delay);
- }
-
-
- for (int x = 0; x < bmp.Width / 4; x += stepCount)
- {
- Rectangle rect1_4 = new Rectangle(bmp.Width / 4 - x - stepCount, 0, 2 * (x + stepCount), bmp.Height);
- dc.DrawImage(bmp, rect1_4, rect1_4, GraphicsUnit.Pixel);
-
- Rectangle rect3_4 = new Rectangle(bmp.Width / 4 * 3 - x - stepCount, 0, 2 * (x + stepCount), bmp.Height);
- dc.DrawImage(bmp, rect3_4, rect3_4, GraphicsUnit.Pixel);
-
- ShowBmp(Rectangle.Union(rect1_4, rect3_4));
- Thread.Sleep(10 * delay);
- }
-
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
-
- #region 对角滑动(改进版)
-
-
- private void Animator20()
- {
- const int movePixel = 4;
- try
- {
- OnDrawStarted(this, EventArgs.Empty);
- ClearBackground();
-
- RectangleF sourRect = new RectangleF(0, 0, bmp.Width, bmp.Height);
- for (int y = bmp.Height; y >= 0; y -= movePixel)
- {
-
- RectangleF destRect = new RectangleF(y * Convert.ToSingle(bmp.Width) / bmp.Height, y, bmp.Width, bmp.Height);
- dc.DrawImage(bmp, destRect, sourRect, GraphicsUnit.Pixel);
-
- ShowBmp(destRect);
- Thread.Sleep(10 * delay);
- }
- }
- catch (Exception ex)
- {
- ShowError(ex.Message);
- }
- finally
- {
- OnDrawCompleted(this, EventArgs.Empty);
- }
- }
-
- #endregion
源程序没有必要解释了,当初编写的时候我就加了非常详细的注释,只要你又一定的.NET基础,应该完全可以读懂!这里是本文的最后一部分:
本文转自 BlackAlpha 51CTO博客,原文链接:http://blog.51cto.com/mengliao/473193,如需转载请自行联系原作者