当前位置: 首页 > news >正文

【自用】C# 中图片切换的几种过渡动画特效

2019独角兽企业重金招聘Python工程师标准>>> hot3.png


//水平百叶窗
public void Effect_BaiYeH(Bitmap obmp, Bitmap bmp, PictureBox pic)
{
	int step = 30;
	try
	{
		Bitmap bmp1 = (Bitmap)bmp.Clone();
		int height = bmp1.Height / step;
		int width = bmp1.Width;
		Graphics g = Graphics.FromImage(obmp);
		Point[] MyPoint = new Point[step];
		for (int y = 0; y < step; y++)
		{
			MyPoint[y].X = 0;
			MyPoint[y].Y = y * height;
		}
		Bitmap bitmap = new Bitmap(bmp.Width, bmp.Height);
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < step; j++)
			{
				for (int k = 0; k < width; k++)
				{
					bitmap.SetPixel(MyPoint[j].X + k, MyPoint[j].Y + i, bmp.GetPixel(MyPoint[j].X + k, MyPoint[j].Y + i));
				}
			}
			pic.Refresh();
			pic.Image = bitmap;

			System.Threading.Thread.Sleep(20);
		}
		g.Dispose();
		bmp1.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}

}

//垂直百叶窗
public void Effect_BaiYeV(Bitmap obmp, Bitmap bmp, PictureBox pic)
{ 
	int step = 50;
	try
	{
		Bitmap bmp1 = (Bitmap)bmp.Clone();
		int dw = bmp1.Width / step;
		int dh = bmp1.Height;
		Graphics g = Graphics.FromImage(obmp);
		Point[] MyPoint = new Point[step];
		for (int x = 0; x < step; x++)
		{
			MyPoint[x].Y = 0;
			MyPoint[x].X = x * dw;
		}
		Bitmap bitmap = new Bitmap(bmp1.Width, bmp1.Height);
		for (int i = 0; i < dw; i++)
		{
			for (int j = 0; j < step; j++)
			{
				for (int k = 0; k < dh; k++)
				{
					bitmap.SetPixel(MyPoint[j].X + i, MyPoint[j].Y + k, bmp1.GetPixel(MyPoint[j].X + i, MyPoint[j].Y + k));
				}
			}
			pic.Refresh();
			pic.Image = bitmap;

			System.Threading.Thread.Sleep(20);
		}
		g.Dispose();
		bmp1.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}
}

//从上向下
public void Effect_U2D(Bitmap obmp, Bitmap bmp, PictureBox pic)
{
	try
	{
		int width = bmp.Width; 
		int height = bmp.Height; 

		Graphics g = pic.CreateGraphics();
		g.DrawImage(obmp, 0, 0, width, height);
		for (int y = 1; y <= height; y += 40)
		{
			Bitmap bitmap = bmp.Clone(new Rectangle(0, 0, width, y), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
			g.DrawImage(bitmap, 0, 0);
			System.Threading.Thread.Sleep(100);
		}
		g.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}
}
//从下向上
public void Effect_D2U(Bitmap obmp, Bitmap bmp, PictureBox pic)
{
	try
	{
		int width = bmp.Width;
		int height = bmp.Height;

		Graphics g = pic.CreateGraphics();
		g.DrawImage(obmp, 0, 0, width, height);

		for (int y = 1; y <= height; y += 40)
		{
			Bitmap bitmap = bmp.Clone(new Rectangle(0, height - y, width, y), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
			g.DrawImage(bitmap, 0, height - y);
			System.Threading.Thread.Sleep(100);
		}
		g.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}
}

//从左向右
public void Effect_L2R(Bitmap obmp, Bitmap bmp, PictureBox pic)
{
	try
	{
		int width = bmp.Width; 
		int height = bmp.Height; 
		Graphics g = pic.CreateGraphics();
		g.DrawImage(obmp, 0, 0, width, height);
		for (int x = 1; x <= width; x += 50)
		{
			Bitmap bitmap = bmp.Clone(new Rectangle(0, 0, x, height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
			g.DrawImage(bitmap, 0, 0);
			System.Threading.Thread.Sleep(100);
		}
		g.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}
}

//从右向左
public void Effect_R2L(Bitmap obmp, Bitmap bmp, PictureBox pic)
{
	try
	{
		int width = bmp.Width;
		int height = bmp.Height;
		Graphics g = pic.CreateGraphics();
		g.DrawImage(obmp, 0, 0, width, height);
		for (int x = 1; x <= width; x += 50)
		{
			//----------------------------------------------w, 0,  0,  h  ||  w-x, 0, +x, h 
			Bitmap bitmap = bmp.Clone(new Rectangle(width - x, 0, x, height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
			g.DrawImage(bitmap, width - x, 0);
			System.Threading.Thread.Sleep(100);
		}
		g.Dispose();
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message, "错误");
	}
}

  作者:  一个吃货帅锅  

转载于:https://my.oschina.net/kilosnow/blog/776451

相关文章:

  • Java应用线上问题排查的常用工具和方法
  • redhat 安装oracle数据库xe版
  • 解决 com.sun.*包导入错误
  • 马哥2016全新Linux+Python高端运维班第九周作业
  • 【求助】小系统组成大系统所遇到的问题
  • Mysql之mysqlbinlog使用
  • css揭秘之linear-gradient
  • Runtime的几个小例子(含Demo)
  • javaList容器中容易忽略的知识点
  • 《AngularJS高级程序设计》学习笔记
  • centos搭建keepalived+ipvsadm实现高可用lvs分发
  • CSS Hack解决浏览器IE部分属性兼容性问题
  • Tripwire强大的服务器文件完整性监测系统-检测并报告服务器***
  • 表单验证插件----jquery validation
  • VS2013编译python源码
  • 《Java编程思想》读书笔记-对象导论
  • ➹使用webpack配置多页面应用(MPA)
  •  D - 粉碎叛乱F - 其他起义
  • express如何解决request entity too large问题
  • HashMap ConcurrentHashMap
  • iOS 系统授权开发
  • JavaScript创建对象的四种方式
  • JavaScript函数式编程(一)
  • JS学习笔记——闭包
  • oldjun 检测网站的经验
  • Redis在Web项目中的应用与实践
  • Spark RDD学习: aggregate函数
  • webgl (原生)基础入门指南【一】
  • WebSocket使用
  • 基于Android乐音识别(2)
  • 浅谈JavaScript的面向对象和它的封装、继承、多态
  • 如何解决微信端直接跳WAP端
  • 如何正确配置 Ubuntu 14.04 服务器?
  • 深入浅出webpack学习(1)--核心概念
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 微服务入门【系列视频课程】
  • 想写好前端,先练好内功
  • 延迟脚本的方式
  • 一文看透浏览器架构
  • 在GitHub多个账号上使用不同的SSH的配置方法
  • 【干货分享】dos命令大全
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • %3cli%3e连接html页面,html+canvas实现屏幕截取
  • (01)ORB-SLAM2源码无死角解析-(66) BA优化(g2o)→闭环线程:Optimizer::GlobalBundleAdjustemnt→全局优化
  • (32位汇编 五)mov/add/sub/and/or/xor/not
  • (4)logging(日志模块)
  • (floyd+补集) poj 3275
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (二)正点原子I.MX6ULL u-boot移植
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (算法)前K大的和
  • (一)Java算法:二分查找
  • (转)shell调试方法
  • (转载)CentOS查看系统信息|CentOS查看命令
  • .NET Project Open Day(2011.11.13)