Java uidevice takescreenshot用于压缩文件的选项无效
我正在使用UI自动机在Junit测试中使用以下命令拍摄低分辨率屏幕截图。所有四个屏幕截图大小相同。我希望它被压缩。如果有其他人能够成功实施,请告诉我。我想得到的只是屏幕的缩略图,而不是高分辨率的屏幕截图。如果可行,建议其他方法Java uidevice takescreenshot用于压缩文件的选项无效,java,android,junit,android-uiautomator,Java,Android,Junit,Android Uiautomator,我正在使用UI自动机在Junit测试中使用以下命令拍摄低分辨率屏幕截图。所有四个屏幕截图大小相同。我希望它被压缩。如果有其他人能够成功实施,请告诉我。我想得到的只是屏幕的缩略图,而不是高分辨率的屏幕截图。如果可行,建议其他方法 getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test1.png")); getUiDevice().takeScreenshot(new File("/sdcard/Pictures/"+"test
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);
用户界面自动机API的Android参考
截图
布尔截图(文件存储路径,
浮标,
int质量)获取当前窗口的屏幕截图,并将其存储为PNG。屏幕截图根据屏幕旋转进行调整
参数storePath文件:PNG应写入的位置
缩放浮动:如果需要,向下缩放屏幕截图;原件为1.0f
大小质量int:PNG压缩的质量;范围:0-100
这是
UiDevice.java
中的takeScreenshot
的实现:
/**
* 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的质量