Exemplo n.º 1
0
        private async void OcrClipboardButton_Click(object sender, RoutedEventArgs e)
        {
            DisableOcrButtons();
            this.ErrorMessageGrid.Visibility = Visibility.Collapsed;

            DataPackageView dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference sr = await dataPackageView.GetBitmapAsync();

                // ※ RandomAccessStreamReference は Dispose 不要

                if (sr != null)
                {
                    if (this.MonitorCameraButton.IsChecked == true)
                    {
                        this.MonitorCameraButton.IsChecked = false;
                    }

                    using (var stream = await sr.OpenReadAsync())
                    {
                        var bitmap = await SoftwareBitmapHelper.ConvertToSoftwareBitmap(stream);
                        await SetImage(bitmap);
                        await RecognizeBitmapAsync(bitmap);
                    }
                }
            }
            else
            {
                await(new MessageDialog("クリップボードに画像がありません", "画像なし"))
                .ShowAsync();
            }
            EnableOcrButtons();
        }
Exemplo n.º 2
0
        private async void OcrCameraButtun_Click(object sender, RoutedEventArgs e)
        {
            DisableOcrButtons();
            this.ErrorMessageGrid.Visibility = Visibility.Collapsed;

            bool isTemp = (_mediaCapture == null);

            if (isTemp)
            {
                await InitializeMediaCaptureAsync();
            }

            var bitmap = await CaputureAsync();

            if (bitmap != null)
            {
                bitmap = SoftwareBitmapHelper.CorrectFormat(bitmap);
                await SetImage(bitmap);
                await RecognizeBitmapAsync(bitmap);

                if (isTemp)
                {
                    await CleanupCameraAsync();
                }

                this.MonitorCameraButton.IsChecked = false;
            }
            EnableOcrButtons();
        }
Exemplo n.º 3
0
        private async void OcrFileButton_Click(object sender, RoutedEventArgs e)
        {
            DisableOcrButtons();
            this.ErrorMessageGrid.Visibility = Visibility.Collapsed;

            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");
            picker.FileTypeFilter.Add(".bmp");
            StorageFile file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                EnableOcrButtons();
                return;
            }

            if (this.MonitorCameraButton.IsChecked == true)
            {
                this.MonitorCameraButton.IsChecked = false;
            }

            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
            {
                var bitmap = await SoftwareBitmapHelper.ConvertToSoftwareBitmap(stream);
                await SetImage(bitmap);
                await RecognizeBitmapAsync(bitmap);
            }
            EnableOcrButtons();
        }
Exemplo n.º 4
0
        private async Task SetImage(SoftwareBitmap bitmap)
        {
            this.Image1.Source = await SoftwareBitmapHelper.CreateBitmapSourceAsync(bitmap);

            this.OverlayCanvas.Width  = bitmap.PixelWidth;
            this.OverlayCanvas.Height = bitmap.PixelHeight;
        }