C#实现图形的平移和缩放

任务

打开一幅图片,实现图片的平移和缩放。

代码

1.	using System;  
2.	using System.Collections.Generic;  
3.	using System.ComponentModel;  
4.	using System.Data;  
5.	using System.Drawing;  
6.	using System.Linq;  
7.	using System.Text;  
8.	using System.Windows.Forms;  
9.	  
10.	namespace WindowsFormsApplication1  
11.	{  
12.	    public partial class Form1 : Form  
13.	    {  
14.	        public Form1()  
15.	        {  
16.	            InitializeComponent();  
17.	        }  
18.	        private string pathname = string.Empty;    
19.	        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)  
20.	        {  
21.	            OpenFileDialog file = new OpenFileDialog();  
22.	            file.InitialDirectory = ".";  
23.	            file.Filter = "所有文件(*.*)|*.*";  
24.	            file.ShowDialog();  
25.	            if (file.FileName != string.Empty)  
26.	            {  
27.	                try  
28.	                {  
29.	                    pathname = file.FileName;   //获得文件的绝对路径  
30.	                    this.pictureBox1.Load(pathname);  
31.	                }  
32.	                catch (Exception ex)  
33.	                {  
34.	                    MessageBox.Show(ex.Message);  
35.	                }  
36.	            }    
37.	        }  
38.	  
39.	        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)  
40.	        {  
41.	            SaveFileDialog save = new SaveFileDialog();  
42.	            save.ShowDialog();  
43.	            if (save.FileName != string.Empty)  
44.	            {  
45.	                pictureBox1.Image.Save(save.FileName);  
46.	            }    
47.	        }  
48.	  
49.	  
50.	  
51.	        private void 上_Click(object sender, EventArgs e)  
52.	        {  
53.	           pictureBox1.Top-=30;  
54.	        }  
55.	  
56.	        private void button1_Click(object sender, EventArgs e)  
57.	        {  
58.	            pictureBox1.Left -= 30;  
59.	        }  
60.	  
61.	        private void button2_Click(object sender, EventArgs e)  
62.	        {  
63.	            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;  
64.	            pictureBox1.Width = pictureBox1.Width * 2;  
65.	            pictureBox1.Height = pictureBox1.Height * 2;  
66.	        }  
67.	  
68.	        private void button3_Click(object sender, EventArgs e)  
69.	        {  
70.	            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;  
71.	            pictureBox1.Width = pictureBox1.Width / 2;  
72.	            pictureBox1.Height = pictureBox1.Height / 2;  
73.	        }  
74.	  
75.	        private void button4_Click(object sender, EventArgs e)  
76.	        {  
77.	            pictureBox1.Left += 30;  
78.	        }  
79.	  
80.	        private void button5_Click(object sender, EventArgs e)  
81.	        {  
82.	            pictureBox1.Top += 30;  
83.	        }  
84.	    }  
85.	} 

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值