Windows Phone 8.1、正在裁剪旋转视频
Windows Phone 8.1, rotating video is being cropped
我必须旋转视频,但遇到以下问题:
第一个(左上)是原视频,大家可以看到,我要旋转90度。在风景中没有问题(右上)。但是当我纵向旋转时(左下角),视频被裁剪了。
我认为问题在于视频有一部分在 phone 之外,并且该部分已被删除,正如您在最后三张图片(右下角)中看到的那样(这就是我的想法,我我不确定这是否是问题所在)。
这是我的代码:
stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
videoPlayer.RenderTransform = new CompositeTransform() { Rotation = rot};
videoPlayer.SetSource(stream, file.FileType);
videoPlayer.Play()
Rect bounds = ApplicationView.GetForCurrentView().VisibleBounds;
switch (rot) {
case -90:
case -270:
case 90:
case 270:
videoPlayer.Height = bounds.Width;
videoPlayer.Width = bounds.Height;
break;
default:
case 0:
case -180:
case 180:
videoPlayer.Height = bounds.Height;
videoPlayer.Width = bounds.Width;
break;
}
在xaml中:
<MediaElement Name="videoPlayer"
AutoPlay="True"
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5"
AreTransportControlsEnabled ="False"/>
谁能告诉我如何在不裁剪的情况下旋转视频?
(拉伸值不影响,我已经尝试了所有可能的值,但没有任何结果,结果相同)
谢谢,
我认为 cropping 的问题是因为 Grid(或其他)面板。它可能会在旋转之前裁剪掉 video/mediaelement,所以在这个变换之后你会看到它是一个正方形。
我已经从评论中尝试了您的代码,并通过使用 Canvas:
设法在不裁剪的情况下旋转视频
<Canvas x:Name="LayoutRoot" Background="Transparent">
<Button x:Name="myBtn" Content="ClickMe button" Click="myBtn_Click"/>
<MediaElement Name="myMedia" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"/>
</Canvas>
private void myBtn_Click(object sender, RoutedEventArgs e)
{
myMedia.Source = new Uri(@"ms-appx:///Test.mp4");
Rect bounds = ApplicationView.GetForCurrentView().VisibleBounds;
myMedia.RenderTransform = new CompositeTransform() { Rotation = 90, TranslateX = -bounds.Width / 2 };
double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
myMedia.Height = bounds.Width * scaleFactor;
myMedia.Width = bounds.Height * scaleFactor;
}
适用于 wp8.1 Silverlight
<Grid>
<Canvas Name="gdPlayer"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<MediaElement x:Name="player"
Stretch="Uniform"
VerticalAlignment="Center"
HorizontalAlignment="Center"
RenderTransformOrigin="0.5 0.5" />
</Canvas>
</Grid>
旋转 90 度
player.RenderTransform = new CompositeTransform() { Rotation = 90, TranslateX = -(Application.Current.Host.Content.ActualHeight / 2), TranslateY = -(Application.Current.Host.Content.ActualWidth / 2) };
player.Height = Application.Current.Host.Content.ActualWidth;
player.Width = Application.Current.Host.Content.ActualHeight;
旋转 0 度
player.RenderTransform = new CompositeTransform() { Rotation = 0, TranslateX = -(Application.Current.Host.Content.ActualWidth / 2), TranslateY = -(Application.Current.Host.Content.ActualHeight / 2) };
player.Height = Application.Current.Host.Content.ActualHeight;
player.Width = Application.Current.Host.Content.ActualWidth;
我必须旋转视频,但遇到以下问题:
第一个(左上)是原视频,大家可以看到,我要旋转90度。在风景中没有问题(右上)。但是当我纵向旋转时(左下角),视频被裁剪了。
我认为问题在于视频有一部分在 phone 之外,并且该部分已被删除,正如您在最后三张图片(右下角)中看到的那样(这就是我的想法,我我不确定这是否是问题所在)。
这是我的代码:
stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
videoPlayer.RenderTransform = new CompositeTransform() { Rotation = rot};
videoPlayer.SetSource(stream, file.FileType);
videoPlayer.Play()
Rect bounds = ApplicationView.GetForCurrentView().VisibleBounds;
switch (rot) {
case -90:
case -270:
case 90:
case 270:
videoPlayer.Height = bounds.Width;
videoPlayer.Width = bounds.Height;
break;
default:
case 0:
case -180:
case 180:
videoPlayer.Height = bounds.Height;
videoPlayer.Width = bounds.Width;
break;
}
在xaml中:
<MediaElement Name="videoPlayer"
AutoPlay="True"
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5"
AreTransportControlsEnabled ="False"/>
谁能告诉我如何在不裁剪的情况下旋转视频?
(拉伸值不影响,我已经尝试了所有可能的值,但没有任何结果,结果相同)
谢谢,
我认为 cropping 的问题是因为 Grid(或其他)面板。它可能会在旋转之前裁剪掉 video/mediaelement,所以在这个变换之后你会看到它是一个正方形。
我已经从评论中尝试了您的代码,并通过使用 Canvas:
设法在不裁剪的情况下旋转视频<Canvas x:Name="LayoutRoot" Background="Transparent">
<Button x:Name="myBtn" Content="ClickMe button" Click="myBtn_Click"/>
<MediaElement Name="myMedia" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"/>
</Canvas>
private void myBtn_Click(object sender, RoutedEventArgs e)
{
myMedia.Source = new Uri(@"ms-appx:///Test.mp4");
Rect bounds = ApplicationView.GetForCurrentView().VisibleBounds;
myMedia.RenderTransform = new CompositeTransform() { Rotation = 90, TranslateX = -bounds.Width / 2 };
double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
myMedia.Height = bounds.Width * scaleFactor;
myMedia.Width = bounds.Height * scaleFactor;
}
适用于 wp8.1 Silverlight
<Grid>
<Canvas Name="gdPlayer"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<MediaElement x:Name="player"
Stretch="Uniform"
VerticalAlignment="Center"
HorizontalAlignment="Center"
RenderTransformOrigin="0.5 0.5" />
</Canvas>
</Grid>
旋转 90 度
player.RenderTransform = new CompositeTransform() { Rotation = 90, TranslateX = -(Application.Current.Host.Content.ActualHeight / 2), TranslateY = -(Application.Current.Host.Content.ActualWidth / 2) };
player.Height = Application.Current.Host.Content.ActualWidth;
player.Width = Application.Current.Host.Content.ActualHeight;
旋转 0 度
player.RenderTransform = new CompositeTransform() { Rotation = 0, TranslateX = -(Application.Current.Host.Content.ActualWidth / 2), TranslateY = -(Application.Current.Host.Content.ActualHeight / 2) };
player.Height = Application.Current.Host.Content.ActualHeight;
player.Width = Application.Current.Host.Content.ActualWidth;