我嘗試創建像描述here截圖:採取截圖,並顯示在表格
private Graphics takeScreenshot()
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
return gfxScreenshot;
}
我怎樣才能顯示它在我的形式拍攝後? 我試圖顯示它一個PictureBox內:
Graphics screenshot = takeScreenshot();
pictureBox1.Image = screenshot;
,但我得到:
嚴重性代碼說明項目文件的線路抑制狀態 錯誤CS0029無法隱式轉換類型「System.Drawing.Graphics」 以 '爲System.Drawing.Image' SRAT C:\用戶\埃德\的文檔\ Visual Studio的 2017年\項目\ SRAT \ SRAT \ Form1.cs的20個活動
的d this answer表示無法將其轉換爲
不要返回'Graphics',回'bmpScreenshot相反。 – Blorgbeard