我已将此功能集成到我的班级库中。一切在功能上都可以正常工作,但是当涉及到GetFileFromPathAsync()
时,尽管我已经添加了try catch,但似乎也没有前进,也不会引发任何异常。
我的类库函数以.dlls的输出路径在单独的文件夹中的方式工作。我使用GUI Application测试该类库,该应用程序将其资源输出到与类库相同的文件夹中。任何帮助,将不胜感激
private static async Task<string> WindowsMediaOCR(string ImagePath, LanguageEnum language)
{
try
{
// ... Some code not related to below code
var file = await StorageFile.GetFileFromPathAsync(Directory.GetCurrentDirectory() +"\\tempImage.bmp")
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
var softwareBitmap = await decoder.GetSoftwareBitmapAsync();
var ocrResult = await engine.RecognizeAsync(softwareBitmap);
string readText = ocrResult.Text;
}
catch(Exception ex)
{
throw;
}
}
尽管我已经添加了try catch,但它似乎也不是
move forward and does not throw any exception
。
问题是WindowsMediaOCR
是异步方法,返回类型为Task<string>
,因此您需要在调用该方法之前放置一个等待关键字。并请更正需要字符串返回类型的上述方法。
var str = await CorLib.WindowsMediaOCR();