python+minicap(二)
一、push文件至手机中
minicap 的使用有很强的针对性,针对不同架构的CPU和SDK制作了不同的 "minicap" 和 "minicap.so" 文件。
获取CPU版本
$ABI=adb shell getprop ro.product.cpu.abi
获取SDK版本
$SDK=adb shell getprop ro.build.version.sdk
1、有一种方法可以成功,可以截图成功的操作:通过adb shell进到手机对应的目录下/data/local/tmp目录下,执行 $LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1080x1920@1080x1920/0 -s > /mnt/sdcard/tmp.jpg 命令就可以,然后再将截图Pull到win电脑中。
2、如果在dos命令提示 符中,直接执行adb shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1080x1920@1080x1920/0 -s > c:\ tmp.jpg ,生成的图片就显示已损坏。
adb shell "$LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1080x1920@1080x1920/0 -s" > c:\ tmp.jpg
另外这是一个shell命令,直接把结果导出到windows端会存在文件头解析的问题(因为手机是linux和windows的编码格式有一些差别导致的)
import os class Banner: def __init__(self):
self.Version = 0 # 版本信息
self.Length = 0 # banner长度
self.Pid = 0 # 进程ID
self.RealWidth = 0 # 设备的真实宽度
self.RealHeight = 0 # 设备的真实高度
self.VirtualWidth = 0 # 设备的虚拟宽度
self.VirtualHeight = 0 #设备的虚拟高度
self.Orientation = 0 # 设备方向
self.Quirks = 0 # 设备信息获取策略 def toString(self):
message = "Banner [Version=" + str(self.Version) + ", length=" + str(self.Length) + ", Pid=" + str(self.Pid) + ", realWidth=" + str(self.RealWidth) + ", realHeight=" + str(self.RealHeight) + ", virtualWidth=" + str(self.VirtualWidth) + ", virtualHeight=" + str(self.VirtualHeight) + ", orientation=" + str(self.Orientation) +", quirks=" + str(self.Quirks) + "]"
return message #!/usr/bin/env python
#-*- coding: utf-8 -*-
'''
Created on 2016年12月29日 @author: fengbo
''' from Banner import Banner
import socket
import threading
from itsdangerous import bytes_to_int
from Queue import Queue 作者:PreFU
链接:https://www.jianshu.com/p/f8b8123cd062
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
class MinicapStream: __instance = None
__mutex = threading.Lock()
def __init__(self):
self.IP = "127.0.0.1" # 定义IP
self.PORT = 1313 # 监听的端口
self.Pid = 0 # 进程ID
self.banner = Banner() # 用于存放banner头信息
# self.minicapSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.minicapSocket=None
self.ReadImageStreamTask = None
self.push = None
self.picture = Queue() @staticmethod
def getBuilder():
"""Return a single instance of TestBuilder object """
if (MinicapStream.__instance == None):
MinicapStream.__mutex.acquire()
if (MinicapStream.__instance == None):
MinicapStream.__instance = MinicapStream()
MinicapStream.__mutex.release()
return MinicapStream.__instance def get_d(self):
print self.picture.qsize()
def run(self):
#开始执行
#启动socket连接
self.minicapSocket= socket.socket(socket.AF_INET,socket.SOCK_STREAM) #定义socket类型,网络通信,TCP
self.minicapSocket.connect((self.IP,self.PORT))
# return self.ReadImageStream()
self.ReadImageStreamTask = threading.Thread(target=self.ReadImageStream).start() def ReadImageStream(self):
#读取图片流到队列 readBannerBytes = 0
bannerLength = 2
readFrameBytes = 0
frameBodylength = 0
dataBody = ""
while True:
reallen=self.minicapSocket.recv(4096)
length = len(reallen)
if not length:
continue
cursor = 0
while cursor < length:
#just do it
if readBannerBytes < bannerLength:
if readBannerBytes==0:
self.banner.Version = bytes_to_int(reallen[cursor])
elif readBannerBytes==1:
bannerLength = bytes_to_int(reallen[cursor])
self.banner.Length = bannerLength
elif readBannerBytes in [2,3,4,5]:
self.banner.Pid += (bytes_to_int(reallen[cursor]) << ((readBannerBytes - 2) * 8)) >> 0;
elif readBannerBytes in [6,7,8,9]:
self.banner.RealWidth += (bytes_to_int(reallen[cursor]) << ((readBannerBytes - 6) * 8)) >> 0;
elif readBannerBytes in [10,11,12,13]:
self.banner.RealHeight += (bytes_to_int(reallen[cursor]) << ((readBannerBytes - 10) * 8)) >> 0;
elif readBannerBytes in [14,15,16,17]:
self.banner.VirtualWidth += (bytes_to_int(reallen[cursor]) << ((readBannerBytes - 14) * 8)) >> 0;
elif readBannerBytes in [18,19,20,21]:
self.banner.VirtualHeight += (bytes_to_int(reallen[cursor]) << ((readBannerBytes - 18) * 8)) >> 0;
elif readBannerBytes == 22:
self.banner.Orientation = bytes_to_int(reallen[cursor])*90
elif readBannerBytes == 23:
self.banner.Quirks = bytes_to_int(reallen[cursor])
cursor += 1
readBannerBytes += 1
if readBannerBytes == bannerLength:
print self.banner.toString()
elif readFrameBytes < 4:
frameBodylength =frameBodylength+ ((bytes_to_int(reallen[cursor])<<(readFrameBytes*8)) >> 0)
cursor += 1
readFrameBytes += 1
else:
if length - cursor >= frameBodylength:
dataBody = dataBody + reallen[cursor:(cursor+frameBodylength)]
if bytes_to_int(dataBody[0])!=0xFF or bytes_to_int(dataBody[1])!=0xD8:
return
self.picture.put(dataBody)
# self.save_file('d:/pic.png', dataBody)
cursor += frameBodylength
frameBodylength = 0
readFrameBytes = 0
dataBody = ""
else:
dataBody = dataBody + reallen[cursor:length]
frameBodylength -= length - cursor;
readFrameBytes += length - cursor;
cursor = length; # adb shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1200x1920@1200x1920/0
# adb forward tcp:1313 localabstract:minicap def save_file(self,file_name, data):
file=open(file_name, "wb")
file.write(data)
file.flush()
file.close() if __name__ == '__main__':
a = MinicapStream.getBuilder()
print id(a)
a.run()
# print a.picture 作者:PreFU
链接:https://www.jianshu.com/p/f8b8123cd062
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
#############################################################################
##
## Copyright (C) 2010 Riverbank Computing Limited.
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
##
## This file is part of the examples of PyQt.
##
## $QT_BEGIN_LICENSE:BSD$
## You may use this file under the terms of the BSD license as follows:
##
## "Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are
## met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in
## the documentation and/or other materials provided with the
## distribution.
## * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
## the names of its contributors may be used to endorse or promote
## products derived from this software without specific prior written
## permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
## $QT_END_LICENSE$
##
############################################################################# from PyQt4 import QtCore, QtGui
from MinicapStream import MinicapStream
import threading
from time import sleep class Screenshot(QtGui.QWidget):
def __init__(self):
super(Screenshot, self).__init__()
self.obje = MinicapStream.getBuilder()
self.inst()
self.picture = self.obje.picture
self.screenshotLabel = QtGui.QLabel()
self.screenshotLabel.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.screenshotLabel.setAlignment(QtCore.Qt.AlignCenter)
self.screenshotLabel.setScaledContents(True)
self.screenshotLabel.setMinimumSize(400, 640) self.createOptionsGroupBox()
self.createButtonsLayout() mainLayout = QtGui.QVBoxLayout()
mainLayout.addWidget(self.screenshotLabel)
mainLayout.addWidget(self.optionsGroupBox)
mainLayout.addLayout(self.buttonsLayout)
self.setLayout(mainLayout) self.shootScreen()
self.delaySpinBox.setValue(5) self.setWindowTitle("Screenshot")
self.resize(480,640) # def resizeEvent(self, event):
# scaledSize = self.originalPixmap.size()
# scaledSize.scale(self.screenshotLabel.size(), QtCore.Qt.KeepAspectRatio)
# if not self.screenshotLabel.pixmap() or scaledSize != self.screenshotLabel.pixmap().size():
# self.updateScreenshotLabel()
def inst(self):
t= threading.Thread(target=self.obje.run)
t.start() def newScreenshot(self):
while True:
if not self.picture.empty():
sleep(0.1)
self.shootScreen()
else:
sleep(0.2) # if self.hideThisWindowCheckBox.isChecked():
# self.hide()
# self.newScreenshotButton.setDisabled(True)
#
# QtCore.QTimer.singleShot(self.delaySpinBox.value() * 1000,
# self.shootScreen) def saveScreenshot(self):
format = 'png'
initialPath = QtCore.QDir.currentPath() + "/untitled." + format fileName = QtGui.QFileDialog.getSaveFileName(self, "Save As",
initialPath,
"%s Files (*.%s);;All Files (*)" % (format.upper(), format))
# if fileName:
# self.originalPixmap.save(fileName, format) def shootScreen(self):
if self.delaySpinBox.value() != 0:
QtGui.qApp.beep() # Garbage collect any existing image first.
self.originalPixmap = None
# self.originalPixmap = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId())
# self.updateScreenshotLabel()
pixmap=QtGui.QPixmap()
pixmap.loadFromData(self.picture.get())
self.screenshotLabel.setPixmap(pixmap);
self.newScreenshotButton.setDisabled(False)
if self.hideThisWindowCheckBox.isChecked():
self.show() def updateCheckBox(self):
if self.delaySpinBox.value() == 0:
self.hideThisWindowCheckBox.setDisabled(True)
else:
self.hideThisWindowCheckBox.setDisabled(False) def createOptionsGroupBox(self):
self.optionsGroupBox = QtGui.QGroupBox("Options") self.delaySpinBox = QtGui.QSpinBox()
self.delaySpinBox.setSuffix(" s")
self.delaySpinBox.setMaximum(60)
self.delaySpinBox.valueChanged.connect(self.updateCheckBox) self.delaySpinBoxLabel = QtGui.QLabel("Screenshot Delay:") self.hideThisWindowCheckBox = QtGui.QCheckBox("Hide This Window") optionsGroupBoxLayout = QtGui.QGridLayout()
optionsGroupBoxLayout.addWidget(self.delaySpinBoxLabel, 0, 0)
optionsGroupBoxLayout.addWidget(self.delaySpinBox, 0, 1)
optionsGroupBoxLayout.addWidget(self.hideThisWindowCheckBox, 1, 0, 1, 2)
self.optionsGroupBox.setLayout(optionsGroupBoxLayout) def createButtonsLayout(self):
self.newScreenshotButton = self.createButton("New Screenshot",
self.newScreenshot) self.saveScreenshotButton = self.createButton("Save Screenshot",
self.saveScreenshot) self.quitScreenshotButton = self.createButton("Quit", self.close) self.buttonsLayout = QtGui.QHBoxLayout()
self.buttonsLayout.addStretch()
self.buttonsLayout.addWidget(self.newScreenshotButton)
self.buttonsLayout.addWidget(self.saveScreenshotButton)
self.buttonsLayout.addWidget(self.quitScreenshotButton) def createButton(self, text, member):
button = QtGui.QPushButton(text)
button.clicked.connect(member)
return button def updateScreenshotLabel(self):
self.screenshotLabel.setPixmap(self.originalPixmap.scaled(
self.screenshotLabel.size(), QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)) if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) screenshot = Screenshot()
screenshot.show()
sys.exit(app.exec_()) 作者:PreFU
链接:https://www.jianshu.com/p/f8b8123cd062
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
python+minicap(二)的更多相关文章
- Python 基础 二
Python 基础 二 今天对昨天学习的Python基础知识进行总结,学而不思则惘,思而不学则殆! 一.先对昨天学习的三大循环的使用情况进行总结: 1.while循环的本质就是让计算机在满足某一条件的 ...
- 初学Python(二)——数组
初学Python(二)——数组 初学Python,主要整理一些学习到的知识点,这次是数组. # -*- coding:utf-8 -*- list = [2.0,3.0,4.0] #计算list长度 ...
- Python学习二:词典基础详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7862377.html 邮箱:moyi@moyib ...
- 有关python下二维码识别用法及识别率对比分析
最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...
- PYTHON练习题 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数。
Python 练习 标签: Python Python练习题 Python知识点 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数,如果大于预设的 ...
- 从Scratch到Python——Python生成二维码
# Python利用pyqrcode模块生成二维码 import pyqrcode import sys number = pyqrcode.create('从Scratch到Python--Pyth ...
- 用python生成二维码
Python生成二维码,可以使用qrcode模块, github地址 我是搬运工 首先安装, 因为打算生成好再展示出来,所以用到Pillow模块 pip install qrcode pip inst ...
- Python 实现二维码生成和识别
今天突然想给自己自己做个头像,然后还是二维码的形式,这样只要扫一扫就可以访问我的主页.然后就开始自己的苦逼之路... 其实实现二维码java,c#,C++等都可以实现:由于自己正在学python,所以 ...
- Python - 模块(二)
目录 Python - 模块(二) re re下面的方法 logging os Python - 模块(二) re re模块提供了正则表达式的相关操作 主要字符介绍: . 通配符,除了换行符之外的任意 ...
- 使用 Python 生成二维码
在“一带一路”国际合作高峰论坛举行期间, 20 国青年投票选出中国的“新四大发明”:高铁.扫码支付.共享单车和网购.其中扫码支付指手机通过扫描二维码跳转到支付页面,再进行付款.这种新的支付方式,造就二 ...
随机推荐
- Linux 下搭建Git 服务器详细步骤
参考: https://www.cnblogs.com/dee0912/p/5815267.html#_label0 https://blog.csdn.net/carfge/article/deta ...
- VisualVM通过ssl远程连接JVM
VisualVM通过密码连接JVM实例如下 https://www.cnblogs.com/qq931399960/p/10960573.html 虽然设置了密码,但还是不够安全,只要获取到密码,在任 ...
- 通过ID获取元素
网页由标签将信息组织起来,而标签的id属性值是唯一的,就像是每人有一个身份证号一样,只要通过身份证号就可以找到相对应的人.那么在网页中,我们通过id先找到标签,然后进行操作. 语法: document ...
- rest 参数与扩展运算符
rest 参数与扩展运算符 1.rest 参数 ES6 引入 rest 参数(形式为...变量名),用于获取函数的多余参数,这样就不需要使用arguments对象了.rest 参数搭配的变量是一个数组 ...
- day01-JavaScript中"Uncaught TypeError: Cannot set property 'innerHTML' of null"错误
转行学开发,代码100天.初写了最简的一段Js代码,即通过document中的innerHTML方法修改一个<p>标签的内容,报以下错误. -"Uncaught TypeErro ...
- 七十:flask钩子函数之关于before_request的钩子函数
在flask中钩子函数是使用特定的装饰器装饰的函数,用于在正常执行的代码中,插入一段自己想要执行的代码(hook) before_first_request:flask项目第一次部署后指向的钩子函数, ...
- AIxoder插件安装及使用
参考:https://www.aixcoder.com/#/Download 右边有快捷导航,查看对应需要的问题 1.下载AIxcoder 2.安装并注册打开 3.给IDE安装 4.验证是否安装成 ...
- Linux 查看操作系统版本信息 uname
Linux 查看操作系统版本信息 uname uname 命令用于显示当前系统的版本信息. 带 -a 选项的 uname 命令会给出当前操作系统的所有有用信息. 命令如下: [root@node1 / ...
- 模拟SQLserver IO压力测试 工具编 SQLIOSIM
描述 最近有业务需求需了解客户的服务器SQLserver 的IO情况,而不仅仅是通过系统计数器 了解硬盘的IO情况或者使用CrystalDiskMark或者Trace重播进行压力测试 .这时SQL S ...
- YAML基础知识及搭建一台简洁版guestbook
一,前言 前面我们已经搭建过简易版k8s集群了,在此基础上可以搭建一个简洁版guestbook ,以便来学习k8s创建pod的整个过程. 二,在此之前,我们还需要学习一下YAML基础知识 YAML 基 ...