裁剪图片内的原始图片?

时间:2014-08-10 08:45:54

标签: c# image crop picturebox

我正在尝试裁剪图像,然后将裁剪图像从预览发送到pictureBox,但pictureBox显示原始图像和裁剪组合。 即时通过Microsoft示例“CSWinFormCropImage”学习裁剪。 MS linke MS link

这是我一直在编辑的代码。

public partial class MainForm : Form
{
    Boolean bHaveMouse;
    Point ptOriginal = new Point();
    Point ptLast = new Point();
    Rectangle rectCropArea;
    Image srcImage = null;

    public MainForm()
    {
        InitializeComponent();
        bHaveMouse = false;
    }

    private void BtnCrop_Click(object sender, EventArgs e)
    {
        TargetPicBox.Size = new Size(rectCropArea.Width, rectCropArea.Height);
        TargetPicBox.Refresh();
        //Prepare a new Bitmap on which the cropped image will be drawn
        Bitmap sourceBitmap = new Bitmap(SrcPicBox.Image, SrcPicBox.Width, SrcPicBox.Height);
        using (Graphics g = Graphics.FromImage(sourceBitmap))
        {
            g.DrawImage(sourceBitmap, new Rectangle(0, 0, TargetPicBox.Width, TargetPicBox.Height), 
            rectCropArea, GraphicsUnit.Pixel);

        }
        TargetPicBox.Image = sourceBitmap;


    }

我没有编辑任何控制裁剪工具的其他代码。因为我认为我的问题是BtnCrop_click和targetPicBox.Image = sourceBitmap。

0 个答案:

没有答案