Windows Phone 8.1媒体捕获旋转不正确

时间:2015-05-18 16:12:55

标签: camera windows-phone-8.1

我很难让我的捕获图像正确旋转,bitmapencoder类似乎没有做任何事情。

    private async Task CapturePhoto()
    {
        ImageEncodingProperties pIEPEncoder = ImageEncodingProperties.CreateJpeg();
        InMemoryRandomAccessStream pIMSCapture = new InMemoryRandomAccessStream();
        using (pIMSCapture)
        {
            await cMCeCapture.CapturePhotoToStreamAsync(pIEPEncoder, pIMSCapture);

            pIMSCapture.Seek(0);

            BitmapDecoder pBDrDecoder = await BitmapDecoder.CreateAsync(pIMSCapture);
            BitmapEncoder pBErEncoder = await BitmapEncoder.CreateForTranscodingAsync(pIMSCapture, pBDrDecoder);
            pBErEncoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant;
            pBErEncoder.BitmapTransform.Rotation = ConvertDegreesToBitmapRotation(cIntRotationDegrees);
            await pBErEncoder.FlushAsync();

            BitmapImage pBIeCapture = new BitmapImage();
            pIMSCapture.Seek(0);
            await pBIeCapture.SetSourceAsync(pIMSCapture);

            CaptureImage.Source = pBIeCapture;
            CaptureImage.Stretch = Stretch.Uniform;
            CaptureImage.Width = LayoutRoot.ActualWidth;
            CaptureImage.Height = LayoutRoot.ActualHeight;
        }

        await CleanupCameraAsync();
    }

任何想法如何解决这个问题?相机API似乎是我最近的克星,所以让任何工作变得如此令人沮丧。

1 个答案:

答案 0 :(得分:0)

我找到了另一种解决方案,并且可以使用从这里获得的WritableBitmapEx类,

https://writeablebitmapex.codeplex.com/

这实际上做了它应该做的事情,不像BitmapEncoder类出于某种原因。此外,它非常易于使用。虽然翻转水平似乎翻转垂直,但不完全确定为什么,但无论如何它仍然有效。我刚刚切换水平和垂直。

    private async Task CapturePhoto()
    {
        ImageEncodingProperties pIEPEncoder = ImageEncodingProperties.CreateJpeg();
        InMemoryRandomAccessStream pIMSCapture = new InMemoryRandomAccessStream();
        using (pIMSCapture)
        {
            await cMCeCapture.CapturePhotoToStreamAsync(pIEPEncoder, pIMSCapture);

            if(!cBlnExternalCamera)
            {
                pIMSCapture.Seek(0);
                BitmapImage pBIeCapture = new BitmapImage();
                await pBIeCapture.SetSourceAsync(pIMSCapture);

                pIMSCapture.Seek(0);
                WriteableBitmap pWBpBitmap = new WriteableBitmap(pBIeCapture.PixelWidth, pBIeCapture.PixelHeight);
                await pWBpBitmap.SetSourceAsync(pIMSCapture);

                if (cIntRotationDegrees != 0)
                    pWBpBitmap = pWBpBitmap.Rotate(cIntRotationDegrees);

                if (cBlnMirroringPreview)
                    pWBpBitmap = pWBpBitmap.Flip(cDInDisplayInformation.CurrentOrientation == DisplayOrientations.Landscape || cDInDisplayInformation.CurrentOrientation == DisplayOrientations.LandscapeFlipped ? WriteableBitmapExtensions.FlipMode.Vertical : WriteableBitmapExtensions.FlipMode.Horizontal);

                CaptureImage.Source = pWBpBitmap;
                CaptureImage.Stretch = Stretch.Uniform;
                CaptureImage.Width = LayoutRoot.ActualWidth;
                CaptureImage.Height = LayoutRoot.ActualHeight;
            }
            else
            {
                pIMSCapture.Seek(0);
                BitmapImage pBIeCapture = new BitmapImage();
                await pBIeCapture.SetSourceAsync(pIMSCapture);

                CaptureImage.Source = pBIeCapture;
                CaptureImage.Stretch = Stretch.Uniform;
                CaptureImage.Width = LayoutRoot.ActualWidth;
                CaptureImage.Height = LayoutRoot.ActualHeight;
            }
        }

        await CleanupCameraAsync();
    }