我有以下问题。我写StackPanel
与CaptureElement
:如何在CaptureElement中旋转摄像头视图?
<StackPanel>
<CaptureElement x:Name="PreviewElement"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="380"
Height="560"
Stretch="UniformToFill"/>
</StackPanel>
在xaml.cs文件视图下:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
cameraCapture = new CameraCapture();
PreviewElement.Source = await cameraCapture.Initialize();
await cameraCapture.StartPreview();
}
而且我有至极类CameraCapture.cs我有所有的方法:
public class CameraCapture
{
MediaCapture mediaCapture;
ImageEncodingProperties imgEncodingProperties;
public async Task<MediaCapture> Initialize(CaptureUse primaryUse = CaptureUse.Photo)
{
//Create media capture and INIT
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
mediaCapture.VideoDeviceController.PrimaryUse = primaryUse;
//Create photo encoding properties as JPEG and set the size that should be use for photo capturing
imgEncodingProperties = ImageEncodingProperties.CreateJpeg();
imgEncodingProperties.Width = 640;
imgEncodingProperties.Height = 480;
return mediaCapture;
}
public async Task StartPreview()
{
//Start preview stream
await mediaCapture.StartPreviewAsync();
}
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desired)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desired);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desired));
}
}
当我在纵向旋转中运行应用程序时,我将摄像头视图顺时针旋转了90度。转到风景视图后,我有一个较小的窗口,其中是相机视图,但旋转很好。
任何想法如何解决这个问题?
你试过'cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);'? – Romasz 2014-11-24 17:40:43
我已经试过这个解决方案,结果是:纵向视图是好的,但横向视图现在旋转-.- – Sowiarz 2014-11-24 20:32:22