Clean up
This commit is contained in:
@@ -159,38 +159,38 @@ def capture_screen_with_cursor():
|
|||||||
hdc = hdc.CreateCompatibleDC()
|
hdc = hdc.CreateCompatibleDC()
|
||||||
hdc.SelectObject(hbmp)
|
hdc.SelectObject(hbmp)
|
||||||
hdc.DrawIcon((0,0), hcursor)
|
hdc.DrawIcon((0,0), hcursor)
|
||||||
|
|
||||||
bmpinfo = hbmp.GetInfo()
|
bmpinfo = hbmp.GetInfo()
|
||||||
bmpstr = hbmp.GetBitmapBits(True)
|
bmpstr = hbmp.GetBitmapBits(True)
|
||||||
cursor = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1).convert("RGBA")
|
cursor = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1).convert("RGBA")
|
||||||
|
|
||||||
win32gui.DestroyIcon(hcursor)
|
win32gui.DestroyIcon(hcursor)
|
||||||
win32gui.DeleteObject(hbmp.GetHandle())
|
win32gui.DeleteObject(hbmp.GetHandle())
|
||||||
hdc.DeleteDC()
|
hdc.DeleteDC()
|
||||||
|
|
||||||
pixdata = cursor.load()
|
pixdata = cursor.load()
|
||||||
|
|
||||||
width, height = cursor.size
|
width, height = cursor.size
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
if pixdata[x, y] == (0, 0, 0, 255):
|
if pixdata[x, y] == (0, 0, 0, 255):
|
||||||
pixdata[x, y] = (0, 0, 0, 0)
|
pixdata[x, y] = (0, 0, 0, 0)
|
||||||
|
|
||||||
hotspot = win32gui.GetIconInfo(hcursor)[1:3]
|
hotspot = win32gui.GetIconInfo(hcursor)[1:3]
|
||||||
|
|
||||||
return (cursor, hotspot)
|
return (cursor, hotspot)
|
||||||
|
|
||||||
cursor, (hotspotx, hotspoty) = get_cursor()
|
cursor, (hotspotx, hotspoty) = get_cursor()
|
||||||
|
|
||||||
ratio = ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100
|
ratio = ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100
|
||||||
|
|
||||||
img = ImageGrab.grab(bbox=None, include_layered_windows=True)
|
img = ImageGrab.grab(bbox=None, include_layered_windows=True)
|
||||||
|
|
||||||
pos_win = win32gui.GetCursorPos()
|
pos_win = win32gui.GetCursorPos()
|
||||||
pos = (round(pos_win[0]*ratio - hotspotx), round(pos_win[1]*ratio - hotspoty))
|
pos = (round(pos_win[0]*ratio - hotspotx), round(pos_win[1]*ratio - hotspoty))
|
||||||
|
|
||||||
img.paste(cursor, pos, cursor)
|
img.paste(cursor, pos, cursor)
|
||||||
|
|
||||||
img.save(file_path)
|
img.save(file_path)
|
||||||
elif user_platform == "Linux":
|
elif user_platform == "Linux":
|
||||||
cursor_obj = Xcursor()
|
cursor_obj = Xcursor()
|
||||||
|
|||||||
Reference in New Issue
Block a user