本人初学C#,此处有点不理解,还请大虾们指教!
下面是一个实现截图功能的代码,程序运行很正常。可就是截图功能在实现时,所显示的部分与所截取的部分分明不一致,求解释。谢了!(附上代码)using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 截图
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Rectangle rect = new Rectangle(0, 0, 0, 0);
        Point p1 = new Point(0, 0);
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "图片(*.jpg)|*.jpg";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmp = new Bitmap(openFileDialog1.FileName.ToString());
                pictureBox1.Image = bmp;
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }        }        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            rect.X = e.X;
            rect.Y = e.Y;
        }        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (e.X < rect.X)
                    p1.X = e.X;
                else
                    p1.X = rect.X;
                if (e.Y < rect.Y)
                    p1.Y = e.Y;
                else
                    p1.Y = rect.Y;
                panel1.Left = pictureBox1.Left + p1.X;
                panel1.Top = pictureBox1.Top + p1.Y;
                panel1.Width = Math.Abs(e.X - rect.X);
                panel1.Height = Math.Abs(e.Y - rect.Y);
                panel1.Visible = true;
            }
            else
                panel1.Visible = false;
        }        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                rect.X = p1.X;
                rect.Y = p1.Y;
                rect.Width = panel1.Width;
                rect.Height = panel1.Height;
                Bitmap bmp = new Bitmap(pictureBox1.Image);
                pictureBox2.Image = bmp.Clone(rect, bmp.PixelFormat);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }        
    }
}

解决方案 »

  1.   

    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage换成 AutoSize 或者 Normal
      

  2.   

    - - 。   差不多代码都在这了。 (实现截图功能的小代码的一点疑惑)  pictureBox1_MouseMove 方法就是获得鼠标 点击开始 到结束的坐标嘛。 加加减减 得到截取的图片宽高。 通过 Bitmap  对象得到图片保存图。
      

  3.   

    pictureBox1中的图像是实际大小吗
      

  4.   

    pictureBox1中的图像是实际大小吗