Here is the code I am using to get an image from the camera (cePuzzle is a CaptureElement & puzzlecapture is a MediaCapture & icPuzzle is an ImageCropper):
Private Async Sub btnStartStopScanning_Click(sender As Object, e As RoutedEventArgs) Handles btnStartStopScanning.Click
Select Case Me.puzzlecapture.CameraStreamState
Case CameraStreamState.NotStreaming
Me.btnStartStopScanning.Content = "Stop Scanning"
Me.btnLookForPuzzle.IsEnabled = False
Me.cePuzzle.Visibility = Visibility.Visible
Me.icPuzzle.Reset()
Await Me.puzzlecapture.StartPreviewAsync()
Case CameraStreamState.Streaming
Me.btnStartStopScanning.Content = "Start Scanning"
Me.btnLookForPuzzle.IsEnabled = True
Me.cePuzzle.Visibility = Visibility.Collapsed
Await Me.puzzlecapture.StopPreviewAsync()
'Create a temporary file for the ImageCropper from the camera
Dim sf As StorageFile = Await ApplicationData.Current.LocalFolder.CreateFileAsync("temppuzzleimage.jpeg", CreationCollisionOption.ReplaceExisting).AsTask()
'Capture the image from the camera
Await Me.puzzlecapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), sf)
'Place the image in the ImageCropper
Await Me.icPuzzle.LoadImageFromFile(sf)
'Case CameraStreamState.BlockedForPrivacy
'Case CameraStreamState.Shutdown
End Select
End Sub
This code works fine, it takes the image & puts it in the ImageCropper, so I can see it & it lets me select a region to crop. However, when I use the following code (which may be incomplete * the OCR is currently commented out, since I have been trying things which were obviously incorrect) it does not seem to work (there is no code there to create the SoftwareBitmap because I was probably doing it wrong as well, so most of this code probably needs rewritten or is missing):
Private Async Sub btnLookForPuzzle_Click(sender As Object, e As RoutedEventArgs) Handles btnLookForPuzzle.Click
Dim sf As StorageFile = Await ApplicationData.Current.LocalFolder.CreateFileAsync("tempcroppedimage.png", CreationCollisionOption.ReplaceExisting)
Dim stream As Streams.IRandomAccessStream = Await sf.OpenAsync(FileAccessMode.ReadWrite)
Await Me.icPuzzle.SaveAsync(stream, BitmapFileFormat.Jpeg)
'Dim bmp As SoftwareBitmap
'Dim ocr As OcrEngine = OcrEngine.TryCreateFromUserProfileLanguages()
'Dim result As OcrResult = Await ocr.RecognizeAsync(bmp)
'For Each textline As OcrLine In result.Lines
' System.Diagnostics.Debug.WriteLine(textline.Text)
'Next
'System.Diagnostics.Debug.WriteLine(result.Text)
End Sub
Everything I have tried would give an OcrResult that has found no results (result.Text is ""). What should I be doing? Thanks.