zoukankan      html  css  js  c++  java
  • python_屏幕截图_区域截图_快捷键

    import time,io
    from PIL import ImageGrab, Image
    import win32clipboard,win32con
    from pynput import keyboard, mouse
    
    folderpath="D:/小姐姐截图/"
    
    def on_release(key):
      if key == keyboard.Key.print_screen:
        screenRegion()
    
    
    # 区域截图left, upper, right, lower
    def screenRegion():
      try:
        left, top = 34, 54
        width, height = 375, 667  # iphone6
        bbox = (left, top, left + width, top + height)
        img = ImageGrab.grab(bbox)
        newfilename = "{}{}.jpg".format(folderpath,int(time.time() * 1000))
        img.save(newfilename)
        
        # 将图片转换为字节流
        output = io.BytesIO()
        img.convert("RGB").save(output, "BMP")
        data = output.getvalue()[14:]
        setClipboard(data)
        print("screen saved!")
      except Exception as e:
        print("error:",e)
    
    
    # 往剪贴板中放入图片
    def setClipboard(data):
      win32clipboard.OpenClipboard()  # 打开剪贴板
      win32clipboard.EmptyClipboard()  # 先清空剪贴板
      win32clipboard.SetClipboardData(win32con.CF_DIB, data)  # 将图片放入剪贴板
      win32clipboard.CloseClipboard()
    
    if __name__ == '__main__':
      listener = keyboard.Listener(on_release=on_release)
      listener.start()
      listener.join()
  • 相关阅读:
    hbase二级索引学习
    redis-cluster集群Mac部署
    http-flume-kafka.conf
    linux 替换文件中的字符串
    flumeDemo
    redis_exporter监控安装
    Hbase内存磁盘大致关系
    spring cloud 尚硅谷学习
    C10K问题
    navicat 远程链接Mysql问题
  • 原文地址:https://www.cnblogs.com/enumx/p/12364889.html
Copyright © 2011-2022 走看看