미디어 요소를 사용하고 싶지만 비디오 사각형의 일부만 표시하고 싶습니다.부분 비디오를 MediaElement
예 : 동영상의 크기가 100x100 픽셀 인 경우 왼쪽의 50x100 픽셀과 같이 동영상의 왼쪽 절반 만 표시하고 싶습니다.
미디어 요소를 사용하고 싶지만 비디오 사각형의 일부만 표시하고 싶습니다.부분 비디오를 MediaElement
예 : 동영상의 크기가 100x100 픽셀 인 경우 왼쪽의 50x100 픽셀과 같이 동영상의 왼쪽 절반 만 표시하고 싶습니다.
당신은이 비디오를자를 것이다 true
에 부정적인 Margins
및 ClipToBounds
세트와 ContentPresenter
에 배치 할 수 있습니다.
MediaElement의 Clip 속성을 설정하여 수행 할 수 있습니다. PathGeometry로 설정할 수 있습니다. 아래는 간단한 예입니다.
XAML :
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="378" Width="472">
<Canvas>
<MediaElement LoadedBehavior="Play" Name="myME" Source="c:\\1.wmv" Width="320" Height="240" Canvas.Left="0" Canvas.Top="0">
</MediaElement>
</Canvas>
</Window>
C#
using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace tests
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
this.MyMedia1.Clip =
new RectangleGeometry(new Rect(0, 0, myME.Width/3, myME.Height));
}
}
}