async private void button_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".bmp"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { try { BitmapImage bitmapImage = new BitmapImage(); IRandomAccessStream stream = await file.OpenReadAsync(); await bitmapImage.SetSourceAsync(stream); image.Source = bitmapImage; Tesseract.BaseApiWinRT tessBaseApi = new Tesseract.BaseApiWinRT(); StorageFolder tessdataFolderobj = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("tessdata"); await tessBaseApi.InitAsync(tessdataFolderobj.Path, "eng"); Rect winrtRect = new Rect(0, 0, 10000, 10000); string result = await tessBaseApi.TesseractRectAsync(stream, winrtRect); textBlock.Text = result; } catch (Exception ex) { textBlock.Text = "ERROR!!! - " + ex.Message; } } }
async private void button_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".bmp"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { try { BitmapImage bitmapImage = new BitmapImage(); IRandomAccessStream stream = await file.OpenReadAsync(); await bitmapImage.SetSourceAsync(stream); image.Source = bitmapImage; Tesseract.BaseApiWinRT tessBaseApi = new Tesseract.BaseApiWinRT(); StorageFolder tessdataFolderobj = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("tessdata"); await tessBaseApi.InitAsync(tessdataFolderobj.Path, "eng"); Rect winrtRect = new Rect(0, 0, 10000, 10000); string result = await tessBaseApi.TesseractRectAsync(stream, winrtRect); textBlock.Text = result; } catch (Exception ex) { textBlock.Text = "ERROR!!! - " + ex.Message; } } }