Вы находитесь на странице: 1из 3

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 Bitmap img = null;
15 double zoom = 1;
16 int defImgWidth;
17 int defImgHeight;
18 Bitmap imeg = null;
19 double zoom1 = 1;
20 int defImgWidth1;
21 int defImgHeight1;
22 public Form1()
23 {
24 InitializeComponent();
25 }
26
27 private void openToolStripMenuItem_Click(object sender, EventArgs e)
28 {
29 if (openFileDialog1.ShowDialog() == DialogResult.OK)
30 {
31 //jadikan mode zoom agarukuran file fit dengan picturebox
32 pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
33
34 //pictureBox1.Load(openFileDialog1.FileName);
35 img = new Bitmap(openFileDialog1.FileName);
36 pictureBox1.Image = img;
37
38 defImgHeight = img.Height;
39 defImgWidth = img.Width;
40 }
41 {
42 if (openFileDialog2.ShowDialog() == DialogResult.OK)
43 {
44 //jadikan mode zoom agarukuran file fit dengan picturebox
45 pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
46
47 //pictureBox1.Load(openFileDialog1.FileName);
48 imeg = new Bitmap(openFileDialog2.FileName);
49 pictureBox2.Image = imeg;
50
51 defImgHeight1 = imeg.Height;
52 defImgWidth1 = imeg.Width;
53 }
54 }
55 }
56
57 private void ZOOMIN_Click(object sender, EventArgs e)
58 {
59 if (img != null)
60 pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
61 zoom = zoom + 0.2;
62 Bitmap bmp = new Bitmap(img, Convert.ToInt32(pictureBox1.Width * zoom),
Convert.ToInt32(pictureBox1.Width * zoom * defImgHeight / defImgWidth));
63 pictureBox1.Image = bmp;
64 // zoom
65 if (imeg != null)
66 pictureBox2.SizeMode = PictureBoxSizeMode.Normal;
67 zoom1 = zoom1 + 0.2;
68 Bitmap bmp1 = new Bitmap(imeg, Convert.ToInt32(pictureBox2.Width *
zoom1), Convert.ToInt32(pictureBox2.Width * zoom1 * defImgHeight1 /
defImgWidth1));
69 pictureBox2.Image = bmp1;
70 }
71
72 private void ZOOMOUT_Click(object sender, EventArgs e)
73 {
74 if (img != null)
75 pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
76 if (zoom > 0.3)
77 {
78 zoom = zoom - 0.2;
79 Bitmap bmp = new Bitmap(img, Convert.ToInt32(pictureBox1.Width *
zoom), Convert.ToInt32(pictureBox1.Width * zoom * defImgHeight /
defImgWidth));
80 pictureBox1.Image = bmp;
81 }
82 {
83 if (imeg != null)
84 pictureBox2.SizeMode = PictureBoxSizeMode.Normal;
85 if (zoom > 0.3)
86 {
87 zoom1 = zoom1 - 0.2;
88 Bitmap bmp1 = new Bitmap(imeg, Convert.ToInt32(pictureBox2.Width
* zoom1), Convert.ToInt32(pictureBox2.Width * zoom1 *
defImgHeight1 / defImgWidth1));
89 pictureBox2.Image = bmp1;
90 }
91 }
92 }
93
94 private void FIT_Click(object sender, EventArgs e)
95 {
96 if (img != null)
97 pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
98 Bitmap bmp = new Bitmap(img, Convert.ToInt32(pictureBox1.Width),
Convert.ToInt32(pictureBox1.Width * defImgHeight / defImgWidth));
99 pictureBox1.Image = bmp;
100 //
101 if (imeg != null)
102 pictureBox2.SizeMode = PictureBoxSizeMode.Normal;
103 Bitmap bmp1 = new Bitmap(img, Convert.ToInt32(pictureBox2.Width),
Convert.ToInt32(pictureBox2.Width * defImgHeight / defImgWidth));
104 pictureBox2.Image = bmp1;
105 }
106
107 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
108 {
109 this.Close();
110 }
111
112 private void button2_Click(object sender, EventArgs e)
113 {
114 pictureBox1.Image = null;
115 pictureBox2.Image = null;
116 }
117
118 private void perhitunganToolStripMenuItem_Click(object sender, EventArgs e)
119 {
120 Form3 form3 = new Form3();
121 form3.Show();
122 }
123
124 private void button3_Click(object sender, EventArgs e)
125 {
126 OpenFileDialog open = new OpenFileDialog();
127 if(open.ShowDialog()==System.Windows.Forms.DialogResult.OK)
128 {
129 Image img = Image.FromFile(open.FileName);
130 img = new Bitmap(new Bitmap(open.FileName), pictureBox1.Width,
pictureBox1.Height);
131 pictureBox1.Image = img;
132 }
133 }
134
135 private void button4_Click(object sender, EventArgs e)
136 {
137 OpenFileDialog open = new OpenFileDialog();
138 if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
139 {
140 Image img = Image.FromFile(open.FileName);
141 img = new Bitmap(new Bitmap(open.FileName), pictureBox2.Width,
pictureBox2.Height);
142 pictureBox2.Image = img;
143 }
144 }
145
146 }
147 }
148

Вам также может понравиться