這應該是非常直接和容易做到的,但它並沒有令人害怕的工作。我想要做的就是畫一些東西到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