制造动画效果

PPT 以动画片方式体现幻灯片是其四个很重点的特征,相信在这之中一定有你喜爱的卡通方式,明日小编就带大家认识三款以动画片格局体现幻灯片的制作方法,由于是GDI+编制程序,
那里以图像取代幻灯片(其实原理是相通的)来演示如何创建以动画片方式显示图像。

证实: 由于是以动画方式呈现图像, 那里不能直接贴静态截图,
由此决定给园友开源,
将具有的可运营代码附在案例背后,
由于具有的动画片处理图像的对象放在都pictureBox控件中,
同时定义的类都黄石小异,
由此那里先把上面案例中要用到的全部类及装载图像的代码给大家,
运营时用这里的代码加上面任意1个实例的代码即可运维程序!
同时楼主保障各样案例代码都编写翻译通过, 绝不忽悠!

绘图类定义及打开图像文件代码

  1. private Bitmap SourceBitmap;
  2. private Bitmap MyBitmap;
  3. private void button2_Click(object sender, EventArgs e)
  4. {
  5. //打开图像文件
  6. OpenFileDialog openFileDialog = new OpenFileDialog();
  7. openFileDialog.Filter = “图像文件(JPeg, Gif, Bmp, etc.)
  8. |*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg图像文件(*.jpg;*.jpeg)
  9. |*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif
    |BMP图像文件(*.bmp)|*.bmp
  10. |Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)|
    *.png |全部文件(*.*)|*.*”;
  11. if (openFileDialog.ShowDialog() == DialogResult.OK)
  12. {
  13. //获得原始大小的图像
  14. SourceBitmap = new Bitmap(openFileDialog.FileName);
  15. //获得缩放后的图像
  16. MyBitmap = new Bitmap(SourceBitmap, this.pictureBox1.Width,
    this.pictureBox1.Height);
  17. this.pictureBox1.Image = MyBitmap;
  18. }
  19. }

复制代码

一. 上述下反转的点子展现图像.

规律: 计算图像地方和惊人后以中度的四分之二为轴实行对换上下半边的图像.

代码:

以上下反转格局呈现图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. int width = this.MyBitmap.Width; //图像宽度
  6. int height = this.MyBitmap.Height; //图像中度
  7. Graphics g = this.panel1.CreateGraphics();
  8. g.Clear(Color.Gray);
  9. for (int i = -width / 2; i <= width / 2; i++)
  10. {
  11. g.Clear(Color.Gray);
  12. int j = Convert.ToInt32(i * (Convert.ToSingle(height) /
    Convert.ToSingle(width)));
  13. Rectangle DestRect = new Rectangle(0, height / 2 -j, width, 2 *
    j);
  14. Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width,
    MyBitmap.Height);
  15. g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
  16. System.Threading.Thread.Sleep(10);
  17. }
  18. }
  19. catch (Exception ex)
  20. {
  21. MessageBox.Show(ex.Message, “消息提醒”);
  22. }
  23. }

复制代码

2. 以上下对接的不贰秘籍展现图像

规律: 首先将图像分为前后两局地, 然后各自展现.

代码:

以上下对接情势突显图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. int width = this.pictureBox壹.Width; //图像宽度
  6. int height = this.pictureBox一.Height; //图像中度
  7. Graphics g = this.panel1.CreateGraphics();
  8. g.Clear(Color.Gray);
  9. Bitmap bitmap = new Bitmap(width, height);
  10. int x = 0;
  11. while (x <= height / 2)
  12. {
  13. for (int i = 0; i <= width – 1; i++)
  14. {
  15. bitmap.SetPixel(i, x, MyBitmap.GetPixel(i, x));
  16. }
  17. for (int i = 0; i <= width – 1; i++)
  18. {
  19. bitmap.SetPixel(i, height – x – 1, MyBitmap.GetPixel(i, height – x –
    1));
  20. }
  21. x++;
  22. this.panel1.Refresh();
  23. g.DrawImage (bitmap,0,0);
  24. System.Threading.Thread.Sleep(10);
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. MessageBox.Show(ex.Message, “信息提醒”);
  30. }
  31. }

复制代码

三. 以四周扩散的办法显示图像

规律: 首先设置图像体现的地方, 然后按中度和宽窄的比重循环输出,
直到高度和幅度为原本大小.

代码:

以四周扩散格局彰显图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. int width = this.MyBitmap.Width; //图像宽度
  6. int height = this.MyBitmap.Height; //图像中度
  7. //取得Graphics对象
  8. Graphics g = this.panel1.CreateGraphics();
  9. g.Clear(Color.格雷); //初叶为全月光蓝
  10. for (int i = 0; i <= width / 2; i++)
  11. {
  12. int j = Convert.ToInt32 (i*(Convert.ToSingle(height) /
    Convert.ToSingle(width)));
  13. Rectangle DestRect = new Rectangle(width / 2 – i, height/2-j, 2 *
    i, 2*j);
  14. Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width,
    MyBitmap.Height);
  15. g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
  16. System.Threading.Thread.Sleep(10);
  17. }
  18. }
  19. catch (Exception ex)
  20. {
  21. MessageBox.Show(ex.Message, “音信提示”);
  22. }
  23. }

复制代码

四. 以平分秋色效果呈现图像

规律: 首先将图分为几块, 再利用 Bitmap 类的
Clone方法从原图钦赐的块中复制图像, 最终将那么些块依次彰显出来便可

代码:

以平分秋色效果展现图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. Graphics g = this.panel1.CreateGraphics();
  4. g.Clear(Color.White);
  5. int width = MyBitmap.Width;
  6. int height = MyBitmap.Height;
  7. //定义将图片切分成多个部分的区域
  8. RectangleF[] block ={
  9. new RectangleF(0,0,width/2,height/2),
  10. new RectangleF(width/2,0,width/2,height/2),
  11. new RectangleF(0,height/2,width/2,height/2),
  12. new RectangleF(width/2,height/2,width/2,height/2)};
  13. //分Buick隆图片的八个部分
  14. Bitmap[] MyBitmapBlack ={
  15. MyBitmap.Clone(block[0],System.Drawing.Imaging.PixelFormat.DontCare),
  16. MyBitmap.Clone(block[1],System.Drawing.Imaging.PixelFormat.DontCare),
  17. MyBitmap.Clone(block[2],System.Drawing.Imaging.PixelFormat.DontCare),
  18. MyBitmap.Clone(block[3],System.Drawing.Imaging.PixelFormat.DontCare)};
  19. //绘制图片的三个部分,各部分绘制时间距离为0.5秒
  20. g.DrawImage(MyBitmapBlack[0], 0, 0);
  21. System.Threading.Thread.Sleep(1000);
  22. g.DrawImage(MyBitmapBlack[1], width / 2, 0);
  23. System.Threading.Thread.Sleep(1000);
  24. g.DrawImage(MyBitmapBlack[3], width / 2, height / 2);
  25. System.Threading.Thread.Sleep(1000);
  26. g.DrawImage(MyBitmapBlack[2], 0, height / 2);
  27. }

复制代码

五. 以淡入淡出效果展现图像

原理: 使用 ImageAttrributes 类的 SetColorMatrix() 方法设置颜色,
调整矩阵达成淡出的效应. 此类还足以对颜色举行改进, 调暗, 调亮和移除等.

代码:

淡入展现效果

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. Graphics g = this.panel1.CreateGraphics();
  6. g.Clear(Color.Gray);
  7. int width = MyBitmap.Width;
  8. int height = MyBitmap.Height;
  9. ImageAttributes attributes = new ImageAttributes();
  10. ColorMatrix matrix = new ColorMatrix();
  11. //创造淡入颜色矩阵
  12. matrix.Matrix00 = (float)0.0;
  13. matrix.Matrix01 = (float)0.0;
  14. matrix.Matrix02 = (float)0.0;
  15. matrix.Matrix03 = (float)0.0;
  16. matrix.Matrix04 = (float)0.0;
  17. matrix.Matrix10 = (float)0.0;
  18. matrix.Matrix11 = (float)0.0;
  19. matrix.Matrix12 = (float)0.0;
  20. matrix.Matrix13 = (float)0.0;
  21. matrix.Matrix14 = (float)0.0;
  22. matrix.Matrix20 = (float)0.0;
  23. matrix.Matrix21 = (float)0.0;
  24. matrix.Matrix22 = (float)0.0;
  25. matrix.Matrix23 = (float)0.0;
  26. matrix.Matrix24 = (float)0.0;
  27. matrix.Matrix30 = (float)0.0;
  28. matrix.Matrix31 = (float)0.0;
  29. matrix.Matrix32 = (float)0.0;
  30. matrix.Matrix33 = (float)0.0;
  31. matrix.Matrix34 = (float)0.0;
  32. matrix.Matrix40 = (float)0.0;
  33. matrix.Matrix41 = (float)0.0;
  34. matrix.Matrix42 = (float)0.0;
  35. matrix.Matrix43 = (float)0.0;
  36. matrix.Matrix44 = (float)0.0;
  37. matrix.Matrix33 = (float)1.0;
  38. matrix.Matrix44 = (float)1.0;
  39. //从0到1展开改动色彩变换矩阵主对角线上的数值
  40. //使二种基准色的饱和度渐增
  41. Single count = (float)0.0;
  42. while (count < 1.0)
  43. {
  44. matrix.Matrix00 = count;
  45. matrix.Matrix11 = count;
  46. matrix.Matrix22 = count;
  47. matrix.Matrix33 = count;
  48. attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default,
    ColorAdjustType.Bitmap);
  49. g.DrawImage(MyBitmap, new Rectangle(0, 0, width, height),
  50. 0, 0, width, height, GraphicsUnit.Pixel, attributes);
  51. System.Threading.Thread.Sleep(200);
  52. count = (float)(count + 0.02);
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. MessageBox.Show(ex.Message, “新闻提醒”);
  58. }
  59. }
  60. 剥离显示图像
  61. private void button3_Click(object sender, EventArgs e)
  62. {
  63. try
  64. {
  65. Graphics g = this.panel1.CreateGraphics();
  66. g.Clear(Color.Gray);
  67. int width = MyBitmap.Width;
  68. int height = MyBitmap.Height;
  69. ImageAttributes attributes = new ImageAttributes();
  70. ColorMatrix matrix = new ColorMatrix();
  71. //创制淡出颜色矩阵
  72. matrix.Matrix00 = (float)0.0;
  73. matrix.Matrix01 = (float)0.0;
  74. matrix.Matrix02 = (float)0.0;
  75. matrix.Matrix03 = (float)0.0;
  76. matrix.Matrix04 = (float)0.0;
  77. matrix.Matrix10 = (float)0.0;
  78. matrix.Matrix11 = (float)0.0;
  79. matrix.Matrix12 = (float)0.0;
  80. matrix.Matrix13 = (float)0.0;
  81. matrix.Matrix14 = (float)0.0;
  82. matrix.Matrix20 = (float)0.0;
  83. matrix.Matrix21 = (float)0.0;
  84. matrix.Matrix22 = (float)0.0;
  85. matrix.Matrix23 = (float)0.0;
  86. matrix.Matrix24 = (float)0.0;
  87. matrix.Matrix30 = (float)0.0;
  88. matrix.Matrix31 = (float)0.0;
  89. matrix.Matrix32 = (float)0.0;
  90. matrix.Matrix33 = (float)0.0;
  91. matrix.Matrix34 = (float)0.0;
  92. matrix.Matrix40 = (float)0.0;
  93. matrix.Matrix41 = (float)0.0;
  94. matrix.Matrix42 = (float)0.0;
  95. matrix.Matrix43 = (float)0.0;
  96. matrix.Matrix44 = (float)0.0;
  97. matrix.Matrix33 = (float)1.0;
  98. matrix.Matrix44 = (float)1.0;
  99. //从1到0实行修改色彩变换矩阵主对角线上的数值
  100. //依次减弱各类色彩分量
  101. Single count = (float)1.0;
  102. while (count > 0.0)
  103. {
  104. matrix.Matrix00 = (float)count;
  105. matrix.Matrix11 = (float)count;
  106. matrix.Matrix22 = (float)count;
  107. matrix.Matrix33 = (float)count;
  108. attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default,
    ColorAdjustType.Bitmap);
  109. g.DrawImage(MyBitmap, new Rectangle(0, 0, width, height),
  110. 0, 0, width, height, GraphicsUnit.Pixel, attributes);
  111. System.Threading.Thread.Sleep(20);
  112. count = (float)(count – 0.01);
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. MessageBox.Show(ex.Message, “音信提示”);
  118. }
  119. }

复制代码

陆. 以左右连接的方法呈现图像

规律: 首先将图像分为左右两局地, 然后各自突显.

代码:

以左右接通格局呈现图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以左右过渡格局展现图像
  4. try
  5. {
  6. int width = this.MyBitmap.Width; //图像宽度
  7. int height = this.MyBitmap.Height; //图像中度
  8. Graphics g = this.panel1.CreateGraphics();
  9. g.Clear(Color.格雷); //开始为全黄铜色
  10. Bitmap bitmap = new Bitmap(width, height);
  11. int x = 0;
  12. while (x <= width / 2)
  13. {
  14. for (int i = 0; i <= height – 1; i++)
  15. {
  16. bitmap.SetPixel(x, i, MyBitmap.GetPixel(x, i));
  17. }
  18. for (int i = 0; i <= height – 1; i++)
  19. {
  20. bitmap.SetPixel(width – x – 1, i,
  21. MyBitmap.GetPixel(width – x – 1, i));
  22. }
  23. x++;
  24. this.panel1.Refresh();
  25. g.DrawImage (bitmap,0,0);
  26. System.Threading.Thread.Sleep(10);
  27. }
  28. }
  29. catch (Exception ex)
  30. {
  31. MessageBox.Show(ex.Message, “音信提醒”);
  32. }
  33. }

复制代码

7. 以左右五花大绑的不二等秘书籍呈现图像

原理: 总计图像地点和冲天后以小幅度的5/10为轴举办对换左右半边的图像.\

代码:

以左右反转方式显示图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以左右反转格局展现图像
  4. try
  5. {
  6. int width = this.MyBitmap.Width; //图像宽度
  7. int height = this.MyBitmap.Height; //图像高度
  8. Graphics g = this.panel1.CreateGraphics();
  9. g.Clear(Color.格雷); //初始为全玉石白
  10. for (int j = -height / 2; j <= height / 2; j++)
  11. {
  12. g.Clear(Color.格雷); //开端为全石磨蓝
  13. int i = Convert.ToInt32(j * (Convert.ToSingle(width) /
    Convert.ToSingle(height)));
  14. Rectangle DestRect = new Rectangle(width / 2 – i, 0, 2 * i,
    height);
  15. Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width,
    MyBitmap.Height);
  16. g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
  17. System.Threading.Thread.Sleep(10);
  18. }
  19. }
  20. catch (Exception ex)
  21. {
  22. MessageBox.Show(ex.Message, “消息提示”);
  23. }
  24. }

复制代码

8. 以从上向下拉伸的方法体现图像

规律: 将图像的上升幅度不变每一回展现图像的1有的, 直到将图片完全展现.

代码:

以从上向下拉伸形式展示图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以从上向下拉伸格局呈现图像
  4. try
  5. {
  6. int width = this.MyBitmap.Width; //图像宽度
  7. int height = this.MyBitmap.Height; //图像中度
  8. Graphics g = this.panel1.CreateGraphics();
  9. g.Clear(Color.格雷); //伊始为全灰湖绿
  10. for (int y = 1; y <= height; y++)
  11. {
  12. Bitmap bitmap=MyBitmap.Clone (new Rectangle(0,0,width ,y),
  13. System.Drawing .Imaging.PixelFormat .Format24bppRgb );
  14. g.DrawImage (bitmap,0,0);
  15. System.Threading.Thread.Sleep(10);
  16. }
  17. }
  18. catch (Exception ex)
  19. {
  20. MessageBox.Show(ex.Message, “消息提醒”);
  21. }
  22. }

复制代码

9. 以从左向右拉伸的形式显示图像

规律:  将图像的莫斯中国科学技术大学学不变每趟突显图像的一片段, 直到将图片完全展现

代码:

以从左向右拉伸方式显示图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {//以从左向右拉伸格局体现图像try
  3. {
  4. int width = this.MyBitmap.Width; //图像宽度
  5. int height = this.MyBitmap.Height; //图像中度
  6. Graphics g = this.panel一.CreateGraphics();g.Clear(Color.格雷);
    //起先为全郎窑红
  7. for (int x = 1; x <= width; x++)
  8. {
  9. Bitmap bitmap=MyBitmap.Clone (new Rectangle
  10. (0,0,x ,height),
  11. System.Drawing .Imaging.PixelFormat .Format24bppRgb );
  12. g.DrawImage (bitmap,0,0);
  13. System.Threading.Thread.Sleep(10);
  14. }
  15. }
  16. catch (Exception ex){MessageBox.Show(ex.Message, “音信提示”);
  17. }
  18. }

复制代码

10. 以自由角度旋转图像

规律: 首要行使了 Graphics 类提供的 RotateTransform()
方法对图像实行旋转.

代码:

以随机角度旋转体现图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以随机角度旋转显示图像
  4. Graphics g = this.panel1.CreateGraphics();
  5. float MyAngle = 0;//旋转的角度
  6. while (MyAngle < 360)
  7. {
  8. TextureBrush MyBrush = new TextureBrush(MyBitmap);
  9. this.panel1.Refresh();
  10. MyBrush.RotateTransform(MyAngle);
  11. g.FillRectangle(MyBrush, 0, 0, this.ClientRectangle.Width,
    this.ClientRectangle.Height);
  12. MyAngle += 0.5f;
  13. System.Threading.Thread.Sleep(50);
  14. }
  15. }

复制代码

拾一. 以椭圆的办法体现图像

规律: 主要使用了 Graphics 类提供的 FillEllipse() 方法和 TextureBrush()
方法.

代码:

椭圆彰显图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //椭圆彰显图像
  4. this.panel1.Refresh();
  5. Graphics g = this.panel1.CreateGraphics();
  6. TextureBrush MyBrush = new TextureBrush(MyBitmap);
  7. g.FillEllipse(MyBrush, this.panel1.ClientRectangle);
  8. }

复制代码

10二. 以不一致的光滑度展现图像.

原理: Graphics 类的 FromArgb() 方法

代码:

以不相同的折射率突显图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以不一致的反射率展现图像
  4. Graphics g = this.panel1.CreateGraphics();
  5. g.SmoothingMode = SmoothingMode.AntiAlias;
  6. TextureBrush MyBrush = new TextureBrush(MyBitmap);
  7. g.FillRectangle(MyBrush, this.panel1.ClientRectangle);
  8. for (int i = 0; i < 255; i++)
  9. {//由透明成为不透明
  10. g.FillRectangle(new
    SolidBrush(Color.FromArgb(i,Color.DarkSlateGray)),
    this.panel1.ClientRectangle);
  11. System.Threading.Thread.Sleep(100);
  12. }
  13. }

复制代码

10三. 以分歧分辨率展现图像

原理: Bitmap 类的 SetResolution 方法

代码:

以差别的分辨率展现图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以区别的分辨率突显图像
  4. Graphics g = this.panel1.CreateGraphics();
  5. for (int i = 10; i < this.panel1.Height; i += 2)
  6. {
  7. g.Clear(Color.Gray);
  8. MyBitmap.SetResolution(i, i);
  9. g.DrawImage(MyBitmap, 0, 0);
  10. System.Threading.Thread.Sleep(100);
  11. }
  12. }

复制代码

⑩4. 以不一样翻转情势呈现图像.

原理: Bitmap 类的 RotateFip()方法

代码:

以分化翻转格局展示图像

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. //以分裂翻转格局展现图像
  4. Graphics g = this.panel1.CreateGraphics();
  5. for (int i = 0; i < 17; i++)
  6. {
  7. switch (i)
  8. {
  9. case 0:
  10. MyBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
  11. break;
  12. case 1:
  13. MyBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
  14. break;
  15. case 2:
  16. MyBitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
  17. break;
  18. case 3:
  19. MyBitmap.RotateFlip(RotateFlipType.Rotate180FlipXY);
  20. break;
  21. case 4:
  22. MyBitmap.RotateFlip(RotateFlipType.Rotate180FlipY);
  23. break;
  24. case 5:
  25. MyBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
  26. break;
  27. case 6:
  28. MyBitmap.RotateFlip(RotateFlipType.Rotate270FlipX);
  29. break;
  30. case 7:
  31. MyBitmap.RotateFlip(RotateFlipType.Rotate270FlipXY);
  32. break;
  33. case 8:
  34. MyBitmap.RotateFlip(RotateFlipType.Rotate270FlipY);
  35. break;
  36. case 9:
  37. MyBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
  38. break;
  39. case 10:
  40. MyBitmap.RotateFlip(RotateFlipType.Rotate90FlipX);
  41. break;
  42. case 11:
  43. MyBitmap.RotateFlip(RotateFlipType.Rotate90FlipXY);
  44. break;
  45. case 12:
  46. MyBitmap.RotateFlip(RotateFlipType.Rotate90FlipY);
  47. break;
  48. case 13:
  49. MyBitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
  50. break;
  51. case 14:
  52. MyBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
  53. break;
  54. case 15:
  55. MyBitmap.RotateFlip(RotateFlipType.RotateNoneFlipXY);
  56. break;
  57. case 16:
  58. MyBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
  59. break;
  60. }
  61. g.Clear(Color.White);
  62. g.DrawImage(MyBitmap, 0, 0);
  63. System.Threading.Thread.Sleep(1000);
  64. }
  65. }

复制代码

十五. ……………

   

太多了, 大多都以1对GDI+类的常用方法,
假诺感兴趣的能够把几个常用类熟谙一下.

协调也能落实广大本性化的以动画格局显示图像.

那里链接明日写的几篇GDI+编制程序方面包车型地铁文章, 要求补课的园友能够进来看1看.
(文/ziyiFly

第一课: C#制作 艺术字

第二课: C#制作
超酷的图像效果

第三课: C#制作 各个总计图

来自:http://www.pin5i.com/showtopic-20239.html

相关文章