小编Soh*_* Hg的帖子

如何在以拉伸模式显示图像的pictureBox中裁剪原始图像?

如何在Stretch模式下显示的pictureBox中裁剪图像?

我在pictureBox中绘制一个矩形:

void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {

        //pictureBox1.Image.Clone();
        xUp = e.X;
        yUp = e.Y;
        Rectangle rec = new Rectangle(xDown, yDown, Math.Abs(xUp - xDown), Math.Abs(yUp - yDown));
        using (Pen pen = new Pen(Color.YellowGreen, 3))
        {

            pictureBox1.CreateGraphics().DrawRectangle(pen, rec);
        }
        rectCropArea = rec;
    }

    void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        pictureBox1.Invalidate();

        xDown = e.X;
        yDown = e.Y;
    }
Run Code Online (Sandbox Code Playgroud)

并使用以下方法裁剪所选部分:

private void btnCrop_Click(object sender, EventArgs e)
    {
        try
        {
            pictureBox3.Refresh();
            //Prepare a new Bitmap on which the cropped image will be drawn
            Bitmap …
Run Code Online (Sandbox Code Playgroud)

c# image crop bitmap picturebox

1
推荐指数
1
解决办法
7733
查看次数

标签 统计

bitmap ×1

c# ×1

crop ×1

image ×1

picturebox ×1