我正在使用以下代码从 WinAppDriver 会话中捕获屏幕截图,然后将其传递给 Tesseract Pix 类以供 OCR 导航 WinAppDriver 会话(Win32 应用程序)无法识别的表中的链接。注意会话是使用 WinAppDriver 定义的WindowsDriver<WindowsElement>
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium;
using System.Configuration;
using Tesseract;
[TestMethod]
public void ImageTest()
{
String ImagePath = @"c:\temp\Image.png";
var screen = session.GetScreenshot();
screen.SaveAsFile(ImagePath, ScreenshotImageFormat.Png);
Pix ImagefromFile = Pix.LoadFromFile(ImagePath); // Works
var screenmemory = session.GetScreenshot().AsByteArray;
Pix ImagefromMemory = Pix.LoadTiffFromMemory(screenmemory); // Fails with "IOExeception: Failed to load image from memory
}
正如评论中所述,我可以将文件保存在本地,然后访问它。但是,我希望通过这个来LoadTiffFromMemory
代替。测试失败,异常System.IO.IOException: Failed to load image from memory