UIAutomator2.0详解(UIDevice篇----截屏)
来源:互联网 发布:数据库 offset 编辑:程序博客网 时间:2024/05/29 19:24
UIDevice为截屏提供了两个接口方法。分别是:
(1)public boolean takeScreenshot(File storePath)
(2)public boolean takeScreenshot(File storePath, float scale, int quality)
查看源码,可以发现方法(1)实质上是对方法(2)的调用,2,3传参分别为1.0和90。
scale为缩小放大比例,quality为压缩质量。quality有效值为【0,100】。
我们再来看一下方法(2)的源码。
可以发现
(1)参数scale并未传给底层。因此,不管scale为何值,其实都无效。
(2)最终实质是对Bitmap的nativeCompress方法的调用。
注:当前UIAutomator源码版本为v18-2.1.2,其他版本可能有差异。
我们再通过测试实验来看一下,对于quality不同值的不同效果。
案例代码如下:
package com.breakloop.u2demo.uidevice;import android.content.Context;import android.support.test.InstrumentationRegistry;import android.util.Log;import org.junit.Test;import java.io.File;import java.io.IOException;/** * Created by user on 2017/11/14. */public class ScreenShotTest extends UIDeviceTest { private String path; private void init(){ Context context= InstrumentationRegistry.getTargetContext(); path=context.getExternalCacheDir().getPath(); Log.i(TAG, "init: path = " + path); } private File createFile(String path,String fileName){ File file=new File(path,fileName); try { if (file.exists()){ file.delete(); } file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return null; } return file; } @Test public void TestCase1(){ init(); File file =createFile(path,"1.png"); Log.i(TAG, "TestCase1: file path = " + file.getPath()); mDevice.takeScreenshot(file,1.0f,10); mDevice.waitForIdle(); }}
执行后,使用adb将图片导出。
1_0.1.png:scale为0.1,quality为100
1_1.png:scale为1,quality为100
1_1_10.png:scale为1,quality为10
1_1_50.png:scale为1,quality为50
1_10.png:scale为1,quality为100
从文件大小来看,竟然无任何差别!测试手机为华为mate9,android7.0
阅读全文
0 0
- UIAutomator2.0详解(UIDevice篇----截屏)
- UIAutomator2.0详解(UIDevice篇---- 序)
- UIAutomator2.0详解(UIDevice篇----Wait)
- UIAutomator2.0详解(UIDevice篇----waitForIdle)
- UIAutomator2.0详解(UIDevice篇----waitForWindowUpdate)
- UIAutomator2.0详解(UIDevice篇----Hierarchy)
- UIAutomator2.0详解(UIDevice篇----performActionAndWait)
- UIAutomator2.0详解(UIDevice篇----UIWatcher)
- UIAutomator2.0详解(UIDevice篇----获取UIDevice对象)
- UIAutomator2.0详解(UIDevice篇----Screen操作)
- UIAutomator2.0详解(UIDevice篇----触屏操作1)
- UIAutomator2.0详解(UIDevice篇----触屏操作2)
- UIAutomator2.0详解(UIDevice篇----触屏操作3)
- UIAutomator2.0详解(UIDevice篇----获取控件)
- UIAutomator2.0详解(UIDevice篇----LastTraversedText质疑)(未解)
- UIAutomator2.0详解(UIDevice篇----获取设备名称和Package名称)
- UIAutomator2.0详解(入门篇)
- UIAutomator2.0详解(JUnit Annotation篇)
- uavcan扩展帧格式
- 解决Windows资源管理器右键菜单打开EditPlus容易导致资源管理器无响应问题
- @SpringApplicationConfiguration(classes = Application.class) 报错,注解不能导入。
- 详解tomcat的连接数与线程池
- 1193分数序列求和
- UIAutomator2.0详解(UIDevice篇----截屏)
- 面向对象进阶 01 对象、类、属性,方法、命名空间
- 欢迎使用CSDN-markdown编辑器
- WSGI的“前世今生”
- Android 教程
- Bootstrap 浏览器/设备支持
- react native之原生和RN的交互
- SQL 性能分析器 SQL Performance Analyzer SPA
- 几何校正