zoukankan      html  css  js  c++  java
  • 图形技术(局部图片的复制)

    using System.Drawing;
    using System.Drawing.Imaging;

    namespace Ex04_03
    {
        public partial class Form1 : Form
        {
            string str;
            public Form1()
            {
                InitializeComponent();
            }

    //选择图片

            private void button1_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
                openFileDialog1.ShowDialog();
                str = openFileDialog1.FileName;
                Image myImage = System.Drawing.Image.FromFile(str);
                pictureBox1.Image = myImage;
                button2.Enabled = true;
            }

    //执行图片复制操作

            private void button2_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == string.Empty || textBox2.Text == string.Empty || textBox3.Text == string.Empty || textBox4.Text == string.Empty)
                {
                    MessageBox.Show("请将要拷贝区域的资料填写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox1.Focus();
                }
                else
                {
                    Graphics graphics = this.CreateGraphics();
                    Bitmap bitmap = new Bitmap(str);
                    Rectangle rectangle = new Rectangle(Convert.ToInt32(textBox1.Text.Trim()), Convert.ToInt32(textBox2.Text.Trim()),
                        Convert.ToInt32(textBox3.Text.Trim()), Convert.ToInt32(textBox4.Text.Trim()));
                    Bitmap cloneBitmap = bitmap.Clone(rectangle, PixelFormat.DontCare);
                    pictureBox2.Image = cloneBitmap;
                }
            }
        }
    }

  • 相关阅读:
    《我是一只IT小小鸟》
    实现对字符串的反转输出与句子的反转输出
    7.13学习记录
    CentOS 7 不能连接网路的解决方法
    Xshell连接linux服务器不成功的乌龙问题
    Python基础(二)数据类型
    Python基础(一)
    UML精粹3
    UML精粹2
    UML精粹1
  • 原文地址:https://www.cnblogs.com/msAspnet/p/2097192.html
Copyright © 2011-2022 走看看