2013-11-28 53 views
3

我已經實現了我自己的取景器和相機邏輯來捕捉圖像。除了一些奇怪的方位問題,它一切正常。用我的應用拍攝的照片可以是縱向或橫向模式。當我通過內置的照片應用瀏覽照片時,其方向與預期一致。當我在連接手機的同時瀏覽來自PC的圖片時,USB USB縮略圖始終處於橫向模式,但是當我打開文件時,照片在縱向模式下正確顯示。當我將我的應用程序中的圖像綁定到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); 

     } 

任何想法?

回答

5

好的,我自己發現了這個問題。在我的旋轉邏輯中,我使用了錯誤的屬性來告訴捕捉設備如何處理手機的當前方向。 我用:

_captureDevice.SetProperty(KnownCameraGeneralProperties.SpecifiedCaptureOrientation, rotation); 

正確的是:

_captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, rotation); 
+0

您可以指定什麼是你的代碼輪換?我得到構建錯誤 – asitis

+1

旋轉是一個整數,它告訴旋轉的程度。當手機在橫向持有手機時,它是0,肖像模式下它是-90,在橫向上它是180 – bitdisaster

+0

謝謝,它解決了我的問題。 –

相關問題