Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从3个PictureBox(不包含图像)中生成一个位图(图像)_C#_Image_Copy_Picturebox - Fatal编程技术网

C# 从3个PictureBox(不包含图像)中生成一个位图(图像)

C# 从3个PictureBox(不包含图像)中生成一个位图(图像),c#,image,copy,picturebox,C#,Image,Copy,Picturebox,在我的表格中,我有3个图片盒。这3个PictureBox具有在其表面绘制的绘制事件。现在我想将3个图片框中的内容组合成一个位图,这样我就可以将完整的内容复制到剪贴板上 然而,我很困惑。我似乎无法将PictureBoxs的内容复制到图像中(因为我正在使用paint事件) 我的代码如下所示: pbPictureBox1_paint(object sender, PaintEventArgs e) { e.graphics.whatever; // there's a _lot_ of draw

在我的表格中,我有3个图片盒。这3个PictureBox具有在其表面绘制的绘制事件。现在我想将3个图片框中的内容组合成一个位图,这样我就可以将完整的内容复制到剪贴板上

然而,我很困惑。我似乎无法将PictureBoxs的内容复制到图像中(因为我正在使用paint事件)

我的代码如下所示:

pbPictureBox1_paint(object sender, PaintEventArgs e)
{
  e.graphics.whatever;  // there's a _lot_ of drawing happening here.
}

pbPictureBox2_paint(object sender, PaintEventArgs e)
{
  e.graphics.whatever;  // there's a _lot_ of drawing happening here.
}

pbPictureBox3_paint(object sender, PaintEventArgs e)
{
  e.graphics.whatever;  // there's a _lot_ of drawing happening here.
}
现在,我想把我所有的PictureBox的内容复制到一个位图,这样我就可以把它复制到剪贴板上。我可以创建一个正确大小的新位图,并将其复制到剪贴板。但无论我做什么,我似乎都无法将PBOX的内容复制到位图中

Bitmap ClipboardBitmap = new Bitmap(correctwidth, correctheight);
// here, I want to copy the contents of pbox1 to some position 0,y of the bitmap
// here, I want to copy the contents of pbox2 to some position x,0 of the bitmap
// here, I want to copy the contents of pbox3 to some position x,y of the bitmap
Clipboard.SetImage(ClipboardBitmap);

不久前,我在我的picturebox上绘图,首先创建一个图像,在图像上绘图,然后将其分配给picturebox。但是,这太慢了(有很多绘画正在进行),所以我不得不求助于_绘画活动。但现在我再也无法从图片盒中取出我的图形了。怎么做?

在忙乱了3个小时没有让它工作之后,当然,在最终决定发布问题后,我会在10分钟内找到答案

以下是如何做到这一点

            // make new bitmap
            Bitmap ClipboardBitmap = new Bitmap(width, height);

            // copy content of pb1 to position 0, y of bitmap
            Rectangle pb1Area = new Rectangle(0, y, labelwidth, labelheigth);
            pb1.DrawToBitmap(ClipboardBitmap, pb1Area);

            // same for pb2 and pb3...

            // copy bitmap to clipboard
            Clipboard.SetImage(ClipboardBitmap);