private void PhotoChooserCompleted(object sender, PhotoResult e)
        {
            this.showInProgress = false;
            if (e.TaskResult == TaskResult.OK)
            {
                // Defensive. This should not happen unless maybe someone programmatically saved a 0 length image in
                // the picture gallery which I am not even sure the phone API will allow.
                // Since this.ocrData.PhotoStream will not accept a zero length stream we'll act defensively here.
                if (e.ChosenPhoto.Length > 0)
                {
                    Stream photoStream;

                    // This is the point where we have a photo available.
                    photoStream = e.ChosenPhoto;

                    // Extract the orientation flag from the photo before we do the scaling down.
                    // If the scaling down is performed we'll no longer have the Exif info in the photo stream.
                    ExifUtils exifUtils = new ExifUtils(OcrClientUtils.GetPhotoBits(photoStream));
                    this.ocrData.ExifOrientationFlag = exifUtils.GetOrientationFlag();

                    if (DoLimitPhotoSize)
                    {
                        photoStream = OcrClientUtils.LimitPhotoSize(photoStream, PhotoMaxSizeDiagonal);
                    }

                    // When setting this.ocrData.PhotoStream, the ocrData instance will notify anyone who subscribed
                    // to its PropertyChanged event. One of the subscribers to PropertyChanged will see that
                    // the PhotoStream became available and it will trigger the OCR conversion.
                    this.ocrData.PhotoStream = photoStream;
                }
            }
        }
Esempio n. 2
0
        private void StartOcrConversion()
        {
            OcrService.RecognizeImageAsync(
                HawaiiClient.HawaiiApplicationId,
                OcrClientUtils.GetPhotoBits(this.ocrData.PhotoStream),
                (output) =>
            {
                // This section defines the body of what is known as an anonymous method.
                // This anonymous method is the callback method
                // called on the completion of the OCR process.
                // Using Dispatcher.BeginInvoke ensures that
                // OnOcrCompleted is invoked on the Main UI thread.
                this.Dispatcher.BeginInvoke(() => OnOcrCompleted(output));
            });

            this.ocrConversionStateManager.OcrConversionState = OcrConversionState.Converting;
            this.Dispatcher.BeginInvoke(() => { this.mainPivot.SelectedIndex = 1; });
        }