0

我想捕获我的表单的一部分并将其绘制在位图变量中......
当我使用 drawToBitmap() 函数并设置rectangle(12,40,...)时,该函数只是从表单的 0,0 点捕获。
那我该怎么做才能解决这个问题?
坦克为您提供帮助

Bitmap bmp = new Bitmap(((int)maxWidth)+2, ((int)maxHeight)+2);
this.DrawToBitmap(bmp,new Rectangle(0,40,((int)maxWidth)+2, ((int)maxHeight)+2));
4

1 回答 1

2

好的,我在这里所做的是创建了一个新表单并添加了一个按钮和一个图片框。当您单击按钮时,它会从窗体中切出一个矩形并将其绘制到图片框。

我使用 -100,0 将图像向左移动 100 像素。

 private void button1_Click(object sender, EventArgs e)
    {
        //The image we will be drawing on then passing to picturebox
        Bitmap bmp=new Bitmap(pictureBox1.Width,pictureBox1.Height);

        using (Graphics g=Graphics.FromImage(bmp))
        {
            using (Bitmap b = new Bitmap(this.Width, this.Height))
            {
                //captures the Form screenschot, and saves it into Bitmap b
                this.DrawToBitmap(b, new Rectangle(0, 0, this.Width, this.Height));

                //this draws the image from Bitmap b starting at the specified location to Bitmap bmp 
                g.DrawImageUnscaled(b, -100, 0);
            }
        }
        //this assigns pictureBox1 the bmp Bitmap.
        pictureBox1.Image = bmp;
    }
于 2012-05-17T13:31:24.603 回答