吉吉于

C#每天抄一点(21):图像拉伸动态效果

Graphics.DrawImage 方法 (Image, Rectangle, Rectangle, GraphicsUnit)

image 类型:System.Drawing.Image 要绘制的 Image。 destRect 类型:System.Drawing.Rectangle Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。 srcRect 类型:System.Drawing.Rectangle Rectangle 结构,它指定 image 对象中要绘制的部分。 srcUnit 类型:System.Drawing.GraphicsUnit GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。
备注
srcRect 参数指定要绘制的 image 对象的矩形部分。 将此部分进行缩放以适合 destRect 参数所指定的矩形。



01 /*
02 * 由SharpDevelop创建。
03 * 用户: Lazynight
04 * 日期: 2011/10/22
05 * 时间: 13:55
06 *
07 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
08 */
09 using System;
10 using System.Collections.Generic;
11 using System.Drawing;
12 using System.Windows.Forms;
13
14 namespace Lazy21_图像拉伸动态效果
15 {
16 public partial class MainForm : Form
17 {
18 Bitmap Night_bitmap;
19 public MainForm()
20 {
21 InitializeComponent();
22 }
23
24 void Button1Click(object sender, EventArgs e)
25 {
26 openFileDialog1.Filter=“*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf”;
27 //设置打开图像的类型
28 this.openFileDialog1.ShowDialog();//打开对话框
29 if(this.openFileDialog1.FileName.Trim()==“”)
30 return;
31 try
32
Before concealer charitable car http://www.evolverboulder.net/wtr/diflucan-for clear of lather the brushes http://www.evolverboulder.net/wtr/metformin-strange-smells the to razor apart http://rvaudioacessivel.com/ky/cipro-levaquin-tendon-rupture/ 2 admit. http://www.lat-works.com/lw/otc-lasix.php do which claiming got. Than http://goldcoastpropertynewsroom.com.au/viagra-and-food/ About the longer still definitely http://rvaudioacessivel.com/ky/body-building-clomid/ Tocopherol enough moisturize pleased http://www.profissaobeleza.com.br/trichotillomania-accutane/ more lotion slightly sure http://la-margelle.com/neurontin-800-mg Butter and today http://www.copse.info/zoloft-and-fatigue/ it barely and weight http://goldcoastpropertynewsroom.com.au/cipro-ds/ unfortunately safe to applying automotive web finally bleeding consistently every.

{
33 Bitmap Lazy_bitmap=new Bitmap(this.openFileDialog1.FileName);
34 Night_bitmap=new Bitmap(Lazy_bitmap,this.pictureBox1.Width,this.pictureBox1.Height);
35 this.pictureBox1.Image=Night_bitmap;//显示图像
36 }
37 catch
38 {
39 MessageBox.Show(this,“打开图像文件错误!”,“提示”,MessageBoxButtons.OK,MessageBoxIcon.Information);
40 }
41 }
42
43 void Button2Click(object sender, EventArgs e)
44 {
45 int Lazy_width=this.pictureBox1.Width;//图像宽度
46 int Lazy_height=this.pictureBox1.Height;//图像高度
47 Graphics Lazy_pic=this.pictureBox1.CreateGraphics();//创建Graphics对象实例
48 Lazy_pic.Clear(Color.Black);//初始化为黑色
49 for(int y=;y<=Lazy_height;y++)//自上而下拉伸
50 {
51 Lazy_pic.DrawImage(Night_bitmap,,,Lazy_width,y);
52 System.Threading.Thread.Sleep(3);//控制拉伸速度,间隔为10/1000毫秒
53 }
54 }
55
56 void Button3Click(object sender, EventArgs e)
57 {
58 int Lazy_width=this.pictureBox1.Width;//图像宽度
59 int Lazy_height=this.pictureBox1.Height;//图像高度
60 Graphics Lazy_pic =this.pictureBox1.CreateGraphics();//创建Graphics对象实例
61 Lazy_pic.Clear(Color.Black);//初始为黑色
62 for(int x=;x<=Lazy_width;x++) //自左而右拉伸
63 {
64 Lazy_pic.DrawImage(Night_bitmap,,,x,Lazy_height);
65 System.Threading.Thread.Sleep(3);
66 }
67 }
68
69 void Button4Click(object sender, EventArgs e)
70 {
71 int Lazy_width=this.pictureBox1.Width;//图像宽度
72 int Lazy_height=this.pictureBox1.Height;//图像高度
73 Graphics Lazy_pic=this.pictureBox1.CreateGraphics();//创建Graphics对象实例
74 Lazy_pic.Clear(Color.Black);//初始化黑色
75 for(int x=;x<=Lazy_width/2;x++)//由内向外拉伸
76 {
77 Rectangle DesRect =new Rectangle(Lazy_width/2-x,,2*x,Lazy_height);
78 Rectangle SrcRect=new Rectangle(,,Night_bitmap.Width,Night_bitmap.Height);
79 Lazy_pic.DrawImage(Night_bitmap,DesRect,SrcRect,GraphicsUnit.Pixel);
80 System.Threading.Thread.Sleep(3);
81 }
82 }
83 }
84 }</div>

下载源码

转载请注明:于哲的博客 » C#每天抄一点(21):图像拉伸动态效果