有貼在微軟GitHub的頁面是相關的兩個樣本,雖然他們面向Windows 10.不過,API應該在8/8.1的工作。
GetPreviewFrame:此示例不會鎖定頁面旋轉,並對預覽流應用糾正旋轉。它不使用SetPreviewRotation
,因爲該方法比使用元數據方法更耗費資源。此示例不捕獲照片(只是預覽幀)
UniversalCameraSample:這一個確實捕獲照片,並支持縱向和橫向方向。下面是相關的部分:
var stream = new InMemoryRandomAccessStream();
try
{
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
var photoOrientation = ConvertOrientationToPhotoOrientation(GetCameraOrientation());
await ReencodeAndSavePhotoAsync(stream, photoOrientation);
}
catch (Exception ex)
{
Debug.WriteLine("Exception when taking a photo: {0}", ex.ToString());
}
有了:
private static async Task ReencodeAndSavePhotoAsync(IRandomAccessStream stream, PhotoOrientation photoOrientation)
{
using (var inputStream = stream)
{
var decoder = await BitmapDecoder.CreateAsync(inputStream);
var file = await KnownFolders.PicturesLibrary.CreateFileAsync("SimplePhoto.jpeg", CreationCollisionOption.GenerateUniqueName);
using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(photoOrientation, PropertyType.UInt16) } };
await encoder.BitmapProperties.SetPropertiesAsync(properties);
await encoder.FlushAsync();
}
}
}
有在樣品仔細看看,看看如何獲得在首位相機的方位(給它一個呼叫正在在我發佈的第一個片段中製作)。
或者,如果您更喜歡視頻,您可以從最近的// build/conference中觀看camera session,其中包括一些相機樣本的漫遊。
您是否嘗試使用SetPreviewRotation而不是SetRecordRotation? – oguzhan 2017-02-02 14:16:13