在寫一此幫助說明類別的文件時,截取的圖片如果還有滑鼠的指標形狀,看起來就更直觀更友善一些。接下來就講如何在截圖中包含滑鼠指標形狀。
[StructLayout(LayoutKind.Sequential)] struct CURSORINFO { public int cbSize; public int flags; public IntPtr hCursor; public Point ptScreenPos; }
[DllImport("user32.dll")] static extern bool GetCursorInfo(out CURSORINFO pci);
private const int CURSOR_SHOWING = 0x00000001;
/// <summary> /// 将鼠标指针形状绘制到屏幕截图上 /// </summary> /// <param name="g"></param> private void DrawCursorImageToScreenImage(ref Graphics g) { if (!this.IsCutCursor) { return; } CURSORINFO vCurosrInfo; vCurosrInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO)); GetCursorInfo(out vCurosrInfo); if ((vCurosrInfo.flags & CURSOR_SHOWING) != CURSOR_SHOWING) return; Cursor vCursor = new Cursor(vCurosrInfo.hCursor); Rectangle vRectangle = new Rectangle(new Point(vCurosrInfo.ptScreenPos.X - vCursor.HotSpot.X, vCurosrInfo.ptScreenPos.Y - vCursor.HotSpot.Y), vCursor.Size); vCursor.Draw(g, vRectangle); }
OK,再去截圖看看吧!
以上是C#開發實例-訂位螢幕截圖工具(十)在截圖中包含滑鼠指標形狀的詳細內容。更多資訊請關注PHP中文網其他相關文章!