gpt4 book ai didi

java - 用于压缩文件的 uidevice takescreenshot 选项不起作用

转载 作者:行者123 更新时间:2023-11-30 01:14:14 27 4
gpt4 key购买 nike

我正在使用 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, float scale, int quality) Take a screenshot of current window and store it as PNG The screenshot is adjusted per screen rotation

Parameters storePath File: where the PNG should be written to scale float: scale the screenshot down if needed; 1.0f for original size quality int: quality of the PNG compression; range: 0-100

最佳答案

这是UiDevice.javatakeScreenshot的实现:

/**
* 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 的质量。

关于java - 用于压缩文件的 uidevice takescreenshot 选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38111579/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com