android 内测截图工具,各种各样的安卓截图方法

今天准备写一下 安卓手机截图的各种方法,再不写我怕以后我自己都会忘记了

差不多从做手机测试开始就开始接触手机的截图方法,陆陆续续的大概有 2 年了。

本篇文章不适合以下人群

伸手党

不喜欢寻根究底的人

本人已知截图的方法

minicap 截图 来自项目openstf 直接读取屏幕缓冲区

adbd 的 framebuffer

screencap 截图(具体分为 rawrgba 和 png 两种)

uiautomator 自动化工具截图

摄像头截图

应该还有其他的方法,只是欢迎留言提醒我

minicap

具体使用方法还是参考我上面链接的比较好

adbd framebuffer

framebuffer service 通过直接读 framebuffer 设备(/dev/graphics/fb0)来截屏,在较新版本的 Android 中,framebuffer service 则调用截屏工具 screencap 来截屏。

screencap png

这种方法简单,但是缺点就是速度太慢

方法

/system/bin/screencap -p screen.png

执行完之后,adb pull 下来就可以了

screencap rawrgba

速度稍微好一些,需要做进一步的处理

为了方便阅读,我直接把关键内容贴到这里

Format:

4 bytes as uint32 - width

4 bytes as uint32 - height

4 bytes as uint32 - pixel format

(width * heigth * bytespp) bytes as byte array - image data, where bytespp is bytes per pixels and depend on pixel format. Usually bytespp is 4.

Info from source code of screencap.

For your example:

00000000 d0 02 00 00 00 05 00 00 01 00 00 00 1e 1e 1e ff

d0 02 00 00 - width - uint32 0x000002d0 = 720

00 05 00 00 - height - uint32 0x00000500 = 1280

01 00 00 00 - pixel format - uint32 0x00000001 = 1 = PixelFormat.RGBA_8888 => bytespp = 4 => RGBA

1e 1e 1e ff - first pixel data - R = 0x1e; G = 0x1e; B = 0x1e; A = 0xff;

Pixels with data stored in array of bytes with size 720*1280*4.

uiautomator 截图

核心代码就一行

UiDevice.getInstance().takeScreenshot(new File("/sdcard/screen.png"));

摄像头截图

清晰度取决于摄像头的清晰度,通常来说清晰度都不高,不适合用于自动化中的图像识别,但是好处就是速度快,非常的快

先来张整体设计图

0189ab2e95571d9e6f782cf40e283507.png

因为摄像头获取到的图片区域往往比较大,所以要先进性预处理

原图

6048cc9ed60e368355ce495af54ab4e0.png

处理后的图

005e44e937869620347d344870c27631.png

我当时为了简单,就是先手动选择屏幕周围的 4 个点,然后用 opencv 做了一下处理,代码也很简单,我直接贴出来了

width = 1920 # screen widthheight = 1080 # screen heightimage = {do it you self} # opencv image object

pts = [[10, 10], [15, 900], [10, 600], [900, 600]] # leftTop, rightTop, leftBottom, rightBottompts1 = np.float32(pts)

pts2 = np.float32([[0, 0], [width, 0], [0, height], [width, height]])

M = cv2.getPerspectiveTransform(pts1, pts2)

image = cv2.warpPerspective(image, M, (width, height))

# show image here

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值