为什么python在保存第二次图像时会花费更多时间?

问题描述

我想在硬盘上保存一个png图像。第一次是1.6秒,而第二次是3秒多,为什么?

import appium.webdriver
from appium import webdriver
import time
import PIL
from PIL import Image
import datetime

"""
Desired Capabilities
"""

desired_cap = {
  "deviceName": "ZY2244B53V","platformName": "Android","appPackage": "==","appActivity": "com.tictok.tictokgame.activities.HomeActivity","automationName": "UiAutomator1"
}
webdriver = webdriver.Remote("http://localhost:4723/wd/hub",desired_cap)
n=0
while n<2:
  a=datetime.utcNow().strftime('%Y-%m-%d %H:%M:%s.%f')[:-3]
  print("time of start saving image" + str(a))
  webdriver.save_screenshot("D:/Python/winzo_memory/a.png")
  b=datetime.utcNow().strftime('%Y-%m-%d %H:%M:%s.%f')[:-3]
  print("time of end saving image" + str(b))

  a=datetime.utcNow().strftime('%Y-%m-%d %H:%M:%s.%f')[:-3]
  print("time of start opening image" + str(a))
  im = Image.open("a.png")
  b=datetime.utcNow().strftime('%Y-%m-%d %H:%M:%s.%f')[:-3]
  print("time of end opening image" + str(b))
  n=n+1

输出

time of start saving image2020-08-23 06:56:41.252
time of end saving image2020-08-23 06:56:42.837
time of start saving image2020-08-23 06:56:42.904
time of end saving image2020-08-23 06:56:45.952

我正在尝试在appium驱动程序中截屏。有没有更快的方法来截屏并让python读取像素?预先感谢。

我的操作系统是Windows7。图像是1080X1920。图像的大小是aprx 1.5 mb。不确定HDD或SSD。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)