系统: 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()
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.