Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Drawing.Imaging;
- using System.Runtime.InteropServices;
- using Graphics;
- using System.Drawing.Printing;
- namespace Graphics
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private Bitmap bmp;
- private Pen pen_for_draw = new Pen(Color.Black, 4);
- private string name_of_image;
- private void button1_Click(object sender, EventArgs e)
- {
- {
- OpenFileDialog open_dialog = new OpenFileDialog();
- open_dialog.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*";
- if (open_dialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- name_of_image = open_dialog.FileName;
- bmp = new Bitmap(open_dialog.FileName);
- this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
- pictureBox1.Image = bmp;
- pictureBox1.Invalidate();
- button2.Visible = true;
- button3.Visible = true;
- button4.Visible = true;
- textBox1.Visible = true;
- textBox2.Visible = true;
- textBox3.Visible = true;
- textBox4.Visible = true;
- textBox5.Visible = true;
- label1.Visible = true;
- label1.Text = bmp.Width.ToString() + " " + bmp.Height.ToString();
- }
- catch
- {
- DialogResult rezult = MessageBox.Show("Impossible to open selected file",
- "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- try
- {
- int per = Int32.Parse(textBox1.Text);
- Image myBitmap = pictureBox1.Image;
- Size nSize = new Size(pictureBox1.Image.Width * per / 100, pictureBox1.Image.Height * per / 100);
- Image gdi = new Bitmap(myBitmap, nSize);
- pictureBox1.Image = gdi;
- }
- catch (Exception er)
- {
- MessageBox.Show(er.Message);
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- button5.Visible = true;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- int x = Int32.Parse(textBox2.Text);
- int y = Int32.Parse(textBox3.Text);
- int width = Int32.Parse(textBox4.Text);
- int height = Int32.Parse(textBox5.Text);
- Image image = pictureBox1.Image;
- Rectangle Rect = new Rectangle(x, y, width - x, height - y);
- Bitmap newb = new Bitmap(Rect.Width, Rect.Height);
- using (var g = System.Drawing.Graphics.FromImage(newb))
- g.DrawImage(image, 0, 0, Rect, GraphicsUnit.Pixel);
- pictureBox1.Image = newb;
- }
- catch (Exception er)
- {
- MessageBox.Show(er.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement