【问题标题】:Windows Phone 8.1, rotating video is being croppedWindows Phone 8.1,正在裁剪旋转视频
【发布时间】:2015-05-13 16:42:59
【问题描述】:

我必须旋转视频,但遇到以下问题:

第一个(左上角)是原始视频,如您所见,我必须旋转 90º。在横向没有问题(右上角)。但是当我纵向旋转时(左下角),视频被裁剪了。

我认为问题在于视频在手机外部有一部分,并且如您在最后三张图片(右下)中看到的那样,该部分已被删除(这是我的想法,我不确定这是不是问题)。

这是我的代码:

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"/>

谁能告诉我如何在不进行裁剪的情况下旋转视频?

(拉伸值不影响,所有可能的值我都试过了,结果一样)

谢谢,

【问题讨论】:

  • 您是否尝试过将对齐方式设置为拉伸而不是居中?
  • 是的,同样的问题:-/
  • 除了Uniform,你有没有尝试过不同的Stretch?您是否也尝试过设置 MediaElement 的高度/宽度?​​
  • 假设 winphone xaml 应用程序的工作方式与 wpf 大致相同,您在使用对齐拉伸时不需要指定宽度和高度,但不确定您是否进行了更改。
  • 不,不顺利,因为它使用旋转前的尺寸,这意味着在纵向它太小(因为高度在宽度之前),而在横向高度太大。

标签: c# windows-phone-8.1 video-player


【解决方案1】:

我认为 cropping 的问题在于 Grid(或其他)面板。它可能会在旋转之前裁剪视频/媒体元素,因此在此转换之后,您会将其视为正方形。

我已经从评论中尝试了您的代码,并设法通过使用 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;
}

【讨论】:

  • 谢谢你uuuu :O¡你是最棒的!
【解决方案2】:

它适用于 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    相关资源
    最近更新 更多