这应该是非常直接和容易做到的,但它并没有令人害怕的工作。我想要做的就是画一些东西到PictureBox
,然后获得PictureBox
内容的快照。下面是我有:DrawToBitmap为什么不绘制其他控件的内容?
Graphics g = pictureBox1.CreateGraphics();
g.DrawImage(_image, _imageRectangle);
using (Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, g))
{
pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
bmp.Save(_filePath);
}
绘制图像出现在画面精细,但一个空白PictureBox
被吸引到_filePath
。这是怎么回事?
如果我猜,我会说pictureBox1.ClientRectangle会有问题。如果要用新的矩形(0,0,pictureBox1.Width,pictureBox1.Height)替换它,会怎么样? – attila
不要使用'CreateGraphics' - 您需要处理'Paint'事件并在那里的图片框上绘制图片。 – Blorgbeard