V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-04-20 21:51:04 +08:00 · 3198 次点击
    这是一个创建于 2571 天前的主题,其中的信息可能已经有所发展或是发生改变。

    系统: 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 条回复    2017-04-21 18:12:20 +08:00
    dianbuixao
        1
    dianbuixao  
       2017-04-20 21:54:31 +08:00
    你真棒
    xuyl
        2
    xuyl  
       2017-04-20 22:44:26 +08:00
    niubility
    Kilerd
        3
    Kilerd  
       2017-04-20 23:49:38 +08:00
    刷新率可以去到多少??? 60HZ ?
    fcj558
        4
    fcj558  
       2017-04-21 00:02:56 +08:00 via iPad
    想起了 iOS 版网易云音乐的锁屏歌词实现方法就是一句歌词一直图片。
    zyqf
        5
    zyqf  
    OP
       2017-04-21 00:03:46 +08:00 via Android
    @Kilerd 目测 0.6Hz ,哈哈
    manhere
        6
    manhere  
       2017-04-21 00:17:24 +08:00
    twoyuan
        7
    twoyuan  
       2017-04-21 18:12:20 +08:00
    Vysor 就蛮好的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1222 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:31 · PVG 01:31 · LAX 10:31 · JFK 13:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.