开发者

How to make a bitmap of the current mouse pointer?

开发者 https://www.devze.com 2023-02-04 04:03 出处:网络
I\'d like to write a screenshot tool in Python. Right now i\'m studying how I could do. I\'ve got a script making a screenshot using win32 api like here, but want to include the mouse pointer in the s

I'd like to write a screenshot tool in Python. Right now i'm studying how I could do. I've got a script making a screenshot using win32 api like here, but want to include the mouse pointer in the screenshot.

With win32gui.GetCursorInfo() i get its state (shown/hidden), its handle and its position. My goal is to use the handle to access the actual bitmap of the cursor, copy it, and add it to my screenshot at the right coordinates开发者_如何学运维. However, I can't seem to find any doc saying what I can do with that handle once I got it.

I'm thinking i might have to do like the screenshot itself, i.e. get a DC of the cursor, create a bitmap compatible with it and copy into it with BitBlt. Am I on the right track?


Does the python win32 api include DrawIconEx:

http://msdn.microsoft.com/en-us/library/ms648065%28v=vs.85%29.aspx

you need to make a drawable context to write it on, and then pass that and the cursor handle...

(or plain DrawIcon)


Anther option is to actually use Python Imaging Library (PIL) you can easily edit bitmap with it. (much simpler then actually using win32 apis.)

you can use ImageGrab, and ImageDraw


Once you get the cursor's icon handle from GetCursorInfo, you can draw it with DrawIcon or DrawIconEx, which I presume the Win32 API module you're using supports. You will need to create a DC for the screenshot bitmap to render the icon to, yes, but I don't think you'll need to create a DC for the cursor icon itself -- DrawIcon should be sufficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消