[英]Rotate a CamerePreviewImageSource
我正在嘗試旋轉CameraPreviewImageSource以使其(僅)以縱向模式顯示:
private async Task InitializeAsync()
{
this.cameraPreviewImageSource = new CameraPreviewImageSource();
DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id;
await cameraPreviewImageSource.InitializeAsync(backCameraId);
VideoEncodingProperties properties = await this.cameraPreviewImageSource.StartPreviewAsync();
double width = 1280;
double height = 720;
this.writeableBitmap = new WriteableBitmap( (int)width, (int)height );
this.capturePreview.Source = this.writeableBitmap;
this.writeableBitmapRenderer = new WriteableBitmapRenderer();
this.jpegRenderer = new JpegRenderer();
this.cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
}
我也在XAML文件中嘗試過,但是大多數情況下結果很奇怪(例如90%的圖片被隱藏了):
<Image x:Name="capturePreview" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3" Width="auto" Height="auto" Canvas.ZIndex="0" >
<Image.RenderTransform>
<CompositeTransform CenterX="0.5" CenterY="0.5" Rotation="90" />
</Image.RenderTransform>
</Image>
有任何想法嗎?
嘗試使用此開關Width和Height,並添加一個RotationFilter並將其旋轉設置為90。還將Device Orientation設置為Portrait 。 如果要在應用程序的其余部分中支持其他方向,只需在OnNavigatedTo / OnNavigatedFrom中設置Orientation 。
private async Task InitializeAsync()
{
this.cameraPreviewImageSource = new CameraPreviewImageSource();
DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id;
await cameraPreviewImageSource.InitializeAsync(backCameraId);
VideoEncodingProperties properties = await this.cameraPreviewImageSource.StartPreviewAsync();
double width = 1280;
double height = 720;
this.writeableBitmap = new WriteableBitmap( (int)height, (int)width );
this.capturePreview.Source = this.writeableBitmap;
var effect = new FilterEffect(m_cameraPreviewImageSource);
effect.Filters = new IFilter[] { new RotationFilter(90) };
this.writeableBitmapRenderer = new WriteableBitmapRenderer(effect);
this.jpegRenderer = new JpegRenderer();
this.cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
m_displayOrientations = DisplayInformation.AutoRotationPreferences;
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
NavigationHelper.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
DisplayInformation.AutoRotationPreferences = m_displayOrientations;
NavigationHelper.OnNavigatedFrom(e);
}
由於您使用諾基亞影像SDK來實現此目的,您是否嘗試過在渲染鏈中添加RotateFilter並在需要時進行旋轉?
您的鏈將是:CameraPreviewSource-> FilterEffect [rotateFilter]-> WriteableBitmapRenderer。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.