2016-01-01 72 views
0

我現在試圖在我的應用程序中實現Tesseract.Xamarin,但沒有任何成功。我面臨的問題與異步方法有關。基本上,在文檔中說:如何實現Tesseract.Xamarin?

TesseractApi api = new TesseractApi (context, AssetsDeployment.OncePerVersion); 
await api.Init ("eng"); 
await api.SetImage("image_path"); 
string text = api.Text; 

我這個確切的代碼是:

TesseractApi api = new TesseractApi(this, AssetsDeployment.OncePerVersion); 
       await api.Init("eng"); 
       await api.SetImage(App._file.Path); 
       string text = api.Text; 

,我得到的是錯誤:「等待」經營者只能異步方法中使用。考慮使用'async'修飾符標記此方法並將其返回類型更改爲'Task' PS我無法修改此方法類型,因爲它是一種覆蓋方法(OnActivityResult)

回答

0

您只需將async關鍵字添加到你的方法(這不會改變方法簽名)

protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data) 
{ 
    TesseractApi api = new TesseractApi(this, AssetsDeployment.OncePerVersion); 
    await api.Init("eng"); 
    await api.SetImage(App._file.Path); 
    string text = api.Text; 
    } 
} 
+0

謝謝你的幫助:) –