uidevice takecreenshot选项压缩文件不工作

时间:2016-06-29 23:15:14

标签: java android junit uiautomator

我正在使用UI Automator在Junit测试中使用以下命令拍摄低分辨率屏幕截图。所有四个屏幕截图都具有相同的大小。我希望它能被压缩。如果其他人能够成功实施它,请告诉我。我想得到屏幕的缩略图,而不是高分辨率的截图。如果可用,建议其他方式。

getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test1.png"));
getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test2.png"),0.1f,10);
getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test3.png"),0.2f,20);
getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test4.png"),1.0f,20);

UI Automator API的Android参考

  

TakeScreenshot

     

boolean takeScreenshot(File storePath,                   浮标,                   int quality)获取当前窗口的屏幕截图并将其存储为PNG屏幕截图根据屏幕旋转进行调整

     

参数storePath文件:应写入PNG的位置   scale float:根据需要缩小屏幕截图; 1.0f原版   size quality int:PNG压缩的质量;范围:0-100

1 个答案:

答案 0 :(得分:1)

这是takeScreenshotUiDevice.java的实施:

/**
 * Take a screenshot of current window and store it as PNG
 *
 * The screenshot is adjusted per screen rotation
 *
 * @param storePath where the PNG should be written to
 * @param scale scale the screenshot down if needed; 1.0f for original size
 * @param quality quality of the PNG compression; range: 0-100
 * @return true if screen shot is created successfully, false otherwise
 * @since API Level 17
 */
public boolean takeScreenshot(File storePath, float scale, int quality) {
    Tracer.trace(storePath, scale, quality);
    return getAutomatorBridge().takeScreenshot(storePath, quality);
}

如您所见,scale完全没有使用,quality仅用于设置保存的PNG的质量。