I'm trying to do some ocr with windows phone 8.1 using this: https://blogs.windows.com/buildingapps/2014/09/18/microsoft-ocr-library-for-windows-runtime/
private async void camera_PhotoConfirmationCaptured(MediaCapture sender, PhotoConfirmationCapturedEventArgs e)
{
try
{
WriteableBitmap bitmap = new WriteableBitmap((int)e.Frame.Width, (int)e.Frame.Height); //crash here
await bitmap.SetSourceAsync(e.Frame);
OcrResult result = await ocr.RecognizeAsync(e.Frame.Height, e.Frame.Width, bitmap.PixelBuffer.ToArray());
foreach (var line in result.Lines)
{
}
}
catch(Exception ex)
{
}
}
private async void takePictureButton_Click(object sender, RoutedEventArgs e)
{
await camera.CapturePhotoToStreamAsync(Windows.Media.MediaProperties.ImageEncodingProperties.CreatePng(), imageStream);
}
I keep getting a crash on the WriteableBitmap constructor and I don't know what to do to fix it. RecognizeAsync must take a writeable bitmap. Here's the exception:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
EDIT1:
I tried this code and got an exception on this line:
WriteableBitmap bitmap = null;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
bitmap = new WriteableBitmap((int)e.Frame.Width, (int)e.Frame.Height); //crash here again
await bitmap.SetSourceAsync(e.Frame);
OcrResult result = await ocr.RecognizeAsync(e.Frame.Height, e.Frame.Width, bitmap.PixelBuffer.ToArray());
foreach (var line in result.Lines)
{
}
});
"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
What do you think is causing this?