使用Photo Capture Device拍摄照片时的方向错误

时间:2013-11-28 06:31:12

标签: windows-phone-8 camera windows-phone

我已经实现了自己的取景器和相机逻辑来捕捉图像。这一切都很好,除了一些奇怪的方向问题。使用我的应用拍摄的照片可以是纵向或横向模式。当我通过内置照片应用程序浏览照片时,方向符合预期。当我通过USB连接手机时从PC浏览图片时,缩略图始终处于横向状态,但是当我打开文件时,照片正好处于纵向模式。当我将应用程序中的图像绑定到Telerik PanAndZoom图像时,方向再次出错。

这是我的初始化代码。

Windows.Foundation.Size best;
            //   Initialize the camera, when available.
            if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                // Use the back camera.
                best = FindBestResolutuion(CameraSensorLocation.Back, AspectRatio.R_16_9);
                _captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, best);
                _captureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, 
            }
            else if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Front))
            {
                // Otherwise, use the front camera.
                best = FindBestResolutuion(CameraSensorLocation.Front);
                _captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Front, best);
            }
            if (Math.Round(best.Width / best.Height, 1) == 1.3)
                _detecteAspectRatio = AspectRatio.R_4_3;
            else
                _detecteAspectRatio = AspectRatio.R_16_9;


            SetOrientation(this.Orientation);
            //Set the VideoBrush source to the camera.

            viewfinderBrush.SetSource(_captureDevice);

这是捕获的代码。

    if (!_capturing)
        {
            _capturing = true;
            _captureMemoryStream = new MemoryStream();
            _thumbnailMemoryStream = new MemoryStream();
            CameraCaptureSequence sequence = _captureDevice.CreateCaptureSequence(1);
            sequence.Frames[0].CaptureStream = _captureMemoryStream.AsOutputStream();
            sequence.Frames[0].ThumbnailStream = _thumbnailMemoryStream.AsOutputStream();
            await _captureDevice.PrepareCaptureSequenceAsync(sequence);
            await sequence.StartCaptureAsync();
            _capturing = false;

            _captureDevice.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
            //Set the stream position to the beginning.
            _captureMemoryStream.Seek(0, SeekOrigin.Begin);
            await _viewModel.CurrentSession.SavePictureAsync(_captureMemoryStream);

        }

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

好的,我自己发现了这个问题。在我的旋转逻辑中,我使用了错误的属性来告诉捕获设备如何处理手机的当前方向。 我用过:

_captureDevice.SetProperty(KnownCameraGeneralProperties.SpecifiedCaptureOrientation, rotation);

正确的是:

_captureDevice.SetProperty( KnownCameraGeneralProperties.EncodeWithOrientation, rotation);