0

我正在使用以下代码从 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

4

1 回答 1

1

屏幕截图很可能不是 TIFF 格式。你能试一下吗?

Pix ImagefromMemory = Pix.LoadFromMemory(screenmemory);

或者

MemoryStream memStream = new MemoryStream();
screen.Save(memStream, ImageFormat.Tiff);
Pix ImagefromMemory = Pix.LoadTiffFromMemory(memStream.ToArray());
于 2019-12-24T04:31:29.200 回答