/// <summary>
        /// Creates a new <see cref="CapturedImageFrame"/> instance from the <paramref name="frame"/> specified.
        /// </summary>
        /// <param name="frame">Captured frame.</param>
        /// <param name="orientation">Camera orientation.</param>
        /// <param name="cameraType">Camera type.</param>
        /// <returns>Captured image frame.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="frame"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="frame"/> stream cannot be read.
        ///     <para>-or-</para>
        /// <paramref name="frame"/> stream is empty.
        /// </exception>
        public static CapturedImageFrame CreateFromCapturedFrame(CapturedFrame frame, PageOrientation orientation, CameraType cameraType)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            if (!frame.CanRead)
            {
                throw new ArgumentException("Frame stream cannot be read.", "frame");
            }

            if (frame.Size == 0)
            {
                throw new ArgumentException("Frame stream is empty.", "frame");
            }

            return(new CapturedImageFrame
            {
                Rotation = OrientationHelper.ConvertOrientationToRotation(orientation, cameraType),
                Flip = OrientationHelper.ConvertOrientationToFlip(orientation, cameraType),
                Stream = frame,
                Height = frame.Height,
                Width = frame.Width
            });
        }
Пример #2
0
        private async Task <Stream> WriteToStreamAsync(CapturedFrame frame)
        {
            using (var outputStream = new InMemoryRandomAccessStream())
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outputStream);

                encoder.IsThumbnailGenerated = false;
                encoder.SetSoftwareBitmap(frame.SoftwareBitmap);

                try
                {
                    await encoder.FlushAsync();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }

                await outputStream.FlushAsync();

                var ms = new MemoryStream();
                await outputStream.AsStream().CopyToAsync(ms);

                ms.Position = 0;

                return(ms);
            }
        }
Пример #3
0
        private void CaptureHandler2(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is IAsyncOperation<TResult>
            var result = frame.FlushAsync();
        }
Пример #4
0
        async private void CaptureHandler1(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is bool
            var result = await frame.FlushAsync();
        }
Пример #5
0
        private async Task SimulateCapturedFrame(CapturedFrame callback)
        {
            await Task.Run(() =>
            {
                while (m_isScanActive)
                {
                    // Assume each frame takes 2 sec to get ready.
                    Task.Delay(2000).Wait();

                    // Invoke callback and pass back frame data to client.
                    callback(frameBuffer);
                }
            });
        }
Пример #6
0
        public async Task <int> StartScanning(CapturedFrame callback)
        {
            int result = -1;

            if (m_isConnectionExist == true)
            {
                // Forward start scan command to the sensor.
                result = 0;

                m_isScanActive = true;

                ScanStarted(null, null);

                await SimulateCapturedFrame(callback);
            }

            return(result);
        }
Пример #7
0
 /// <summary>
 /// The <see cref="VariablePhotoCapture.PhotoCaptured"/> event handler.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="capturedFrame">Captured frame.</param>
 private void VariableCaptureOnPhotoCaptured(object sender, CapturedFrame capturedFrame)
 {
     Tracing.Trace("PhotoCamera: Variable frame captured.");
     this.NotifyPhotoCaptured(CapturedImageFrame.CreateFromCapturedFrame(capturedFrame, this.Orientation, this.CameraType));
 }
Пример #8
0
 public void SetPixels(CapturedFrame frame)
 {
     this.SetPixels(frame.SoftwareBitmap);
 }
Пример #9
0
 /// <summary>
 /// The <see cref="VariablePhotoCapture.PhotoCaptured"/> event handler.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="capturedFrame">Captured frame.</param>
 private void VariableCaptureOnPhotoCaptured(object sender, CapturedFrame capturedFrame)
 {
     Tracing.Trace("PhotoCamera: Variable frame captured.");
     this.NotifyPhotoCaptured(CapturedImageFrame.CreateFromCapturedFrame(capturedFrame, this.Orientation, this.CameraType));
 }
Пример #10
0
        /// <summary>
        /// Creates a new <see cref="CapturedImageFrame"/> instance from the <paramref name="frame"/> specified.
        /// </summary>
        /// <param name="frame">Captured frame.</param>
        /// <param name="orientation">Camera orientation.</param>
        /// <param name="cameraType">Camera type.</param>
        /// <returns>Captured image frame.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="frame"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="frame"/> stream cannot be read.
        ///     <para>-or-</para>
        /// <paramref name="frame"/> stream is empty.
        /// </exception>
        public static CapturedImageFrame CreateFromCapturedFrame(CapturedFrame frame, PageOrientation orientation, CameraType cameraType)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            if (!frame.CanRead)
            {
                throw new ArgumentException("Frame stream cannot be read.", "frame");
            }

            if (frame.Size == 0)
            {
                throw new ArgumentException("Frame stream is empty.", "frame");
            }

            return new CapturedImageFrame
            {
                Rotation = OrientationHelper.ConvertOrientationToRotation(orientation, cameraType),
                Flip     = OrientationHelper.ConvertOrientationToFlip(orientation, cameraType),
                Stream   = frame,
                Height   = frame.Height,
                Width    = frame.Width
            };
        }