推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
zyqf
V2EX  ›  Python

38 行代码实现传输 Android 实时画面

  •  
  •   zyqf · Apr 20, 2017 · 4039 views
    This topic created in 3483 days ago, the information mentioned may be changed or developed.

    系统: Ubantu 16 lts

    思路: TK 显示 + adb 循环截图

    注意:把脚本和 adb 执行文件放在同一目录下

    效果:

    其实是实时刷新的,只是截图是静态的。

    完整记录: https://www.sspanda.com/python-38xing-dai-ma-shi-xian-androidshi-shi-hua-mian/

    # -*- coding:utf-8 -*-
    import io,os  
    from PIL import Image, ImageTk  
    import Tkinter as tk  
    import time  
    whbox ={"w_box":800,"h_box":800}  
    root = tk.Tk()  
    root.title("录频脚本")  
    root.geometry('450x800')  
    def resize(w, h, w_box, h_box, pil_image):  
        f1 = 1.0*w_box/w  
        f2 = 1.0*h_box/h
        factor = min([f1, f2])
        width = int(w*factor)
        height = int(h*factor)
        return pil_image.resize((width, height), Image.ANTIALIAS)
    def Get_pic():  
        w_box = whbox['w_box']
        h_box = whbox['h_box']
        image_bytes = os.popen('./adb shell screencap -p').read() 
        data_stream = io.BytesIO(image_bytes)
        pil_image = Image.open(data_stream)
        w, h = pil_image.size
        pil_image_resized = resize(w, h, w_box, h_box, pil_image)
        wr, hr = pil_image_resized.size
        tk_image = ImageTk.PhotoImage(pil_image_resized)
        return tk_image
    
    def flushpic():  
        bgm = Get_pic()
        label.configure(image = bgm)
        label.image = bgm
        root.after(1, flushpic)
    bgm = Get_pic()  
    label = tk.Label(root,image=bgm,width=whbox['w_box'], height=whbox['h_box']  
    )
    label.pack()  
    root.after(0,flushpic)  
    root.mainloop()  
    
    7 replies  •  2017-04-21 18:12:20 +08:00
    dianbuixao
    dianbuixao
    Apr 20, 2017
    1
    你真棒
    xuyl
    xuyl
    Apr 20, 2017
    2
    niubility
    Kilerd
    Kilerd
    Apr 20, 2017
    3
    刷新率可以去到多少??? 60HZ ?
    fcj558
    fcj558
    Apr 21, 2017 via iPad
    4
    想起了 iOS 版网易云音乐的锁屏歌词实现方法就是一句歌词一直图片。
    zyqf
    zyqf
    OP
    Apr 21, 2017 via Android
    5
    @Kilerd 目测 0.6Hz ,哈哈
    twoyuan
    twoyuan
    Apr 21, 2017
    7
    Vysor 就蛮好的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2883 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:17 · PVG 21:17 · LAX 05:17 · JFK 08:17
    ♥ Do have faith in what you're doing.