Reputation: 146
I have implemented my own viewfinder and camera logic to capture images. It all works fine except some weird orientation problems. The photos taken with my app can be in portrait or landscape mode. When I browse the photos via the built-in photo app the orientation is as expected. When I browse the pictures from PC while the phone is connected vi USB the thumbnails are always in landscape but when I open the file the photo is correctly in portrait mode. When I bind the images in my app to a Telerik PanAndZoom image then again the orientation is wrong.
Here my initialization code.
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);
That's the code for capturing.
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);
}
Any idea?
Upvotes: 3
Views: 1740
Reputation: 146
Ok, I found the problem myself. In my rotation logic I used the wrong property to tell the capture device how to handle the current orientation of the phone. I used:
_captureDevice.SetProperty(KnownCameraGeneralProperties.SpecifiedCaptureOrientation, rotation);
Correct is:
_captureDevice.SetProperty( KnownCameraGeneralProperties.EncodeWithOrientation, rotation);
Upvotes: 5