利用python编写一个类似QQ截图的小工具应该怎么入手
1个回答
展开全部
# -*- coding: utf-8 -*-
import pythoncom
import pyHook
import time
import win32api
import win32con
from pymouse import PyMouse
from PIL import ImageGrab
mouse = PyMouse()
start = list()
end = list()
def on_mouse_left_down(event):
global start
start = mouse.position()
return True
def on_mouse_left_up(event):
global end
end = mouse.position()
if start[0] < end[0] and start[1] < end[1]:
start_x = start[0]
start_y = start[1]
end_x = end[0]
end_y = end[1]
elif start[0] > end[0] and start[1] < end[1]:
start_x = end[0]
start_y = start[1]
end_x = start[0]
end_y = end[1]
elif start[0] < end[0] and start[1] > end[1]:
start_x = start[0]
start_y = end[1]
end_x = end[0]
end_y = start[1]
elif start[0] > end[0] and start[1] > end[1]:
start_x = end[0]
start_y = end[1]
end_x = start[0]
end_y = start[1]
else:
return True
grab_tuple = (start_x, start_y, end_x, end_y)
print grab_tuple
im = ImageGrab.grab(grab_tuple)
im.save("test.jpg", 'jpeg')
return True
hm = pyHook.HookManager()
hm.MouseLeftDown = on_mouse_left_down
hm.MouseLeftUp = on_mouse_left_up
hm.HookMouse()
pythoncom.PumpMessages()
再做个屏幕遮罩就完美啦
import pythoncom
import pyHook
import time
import win32api
import win32con
from pymouse import PyMouse
from PIL import ImageGrab
mouse = PyMouse()
start = list()
end = list()
def on_mouse_left_down(event):
global start
start = mouse.position()
return True
def on_mouse_left_up(event):
global end
end = mouse.position()
if start[0] < end[0] and start[1] < end[1]:
start_x = start[0]
start_y = start[1]
end_x = end[0]
end_y = end[1]
elif start[0] > end[0] and start[1] < end[1]:
start_x = end[0]
start_y = start[1]
end_x = start[0]
end_y = end[1]
elif start[0] < end[0] and start[1] > end[1]:
start_x = start[0]
start_y = end[1]
end_x = end[0]
end_y = start[1]
elif start[0] > end[0] and start[1] > end[1]:
start_x = end[0]
start_y = end[1]
end_x = start[0]
end_y = start[1]
else:
return True
grab_tuple = (start_x, start_y, end_x, end_y)
print grab_tuple
im = ImageGrab.grab(grab_tuple)
im.save("test.jpg", 'jpeg')
return True
hm = pyHook.HookManager()
hm.MouseLeftDown = on_mouse_left_down
hm.MouseLeftUp = on_mouse_left_up
hm.HookMouse()
pythoncom.PumpMessages()
再做个屏幕遮罩就完美啦
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询