12
我使用下面的代碼來捕獲位圖中的屏幕。屏幕被捕獲,但我無法獲得屏幕上的鼠標指針。你能否提出一些替代方法,以便捕獲鼠標?如何使用Windows API捕獲屏幕和鼠標指針?
private Bitmap CaptureScreen()
{
// Size size is how big an area to capture
// pointOrigin is the upper left corner of the area to capture
int width = Screen.PrimaryScreen.Bounds.X + Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Y + Screen.PrimaryScreen.Bounds.Height;
Size size = new Size(width, height);
Point pointOfOrigin = new Point(0, 0);
Bitmap bitmap = new Bitmap(size.Width, size.Height);
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(pointOfOrigin, new Point(0, 0), size);
}
return bitmap;
}
}
尼斯,乾淨,快速的代碼。謝謝。 –
請注意,此代碼會在錯誤的位置繪製一些光標,因爲您需要爲偏移調用「GetIconInfo」。另外一些會出現褪色,更多詳細信息請參閱:http://stackoverflow.com/questions/918990/ – WhoIsRich