I am creating an app with WPF and I need to render a video with transparent background. Does anyone know of a tool or way to do it efficiently?
As far as I know WPF does not natively support rendering videos with transparent background or alpa channel. I have tried to extract each image of the video in a .png and then render it 1 by 1, as you can imagine this is not the most efficient.
Here is the code I am currently using to render the video (it doesn't support transparency)
MediaElement video = new MediaElement
{
Source = new Uri(videoFile, UriKind.RelativeOrAbsolute),
Name = objectID,
Width = width,
Height = height,
Opacity = transparency,
Volume = mute ? 0 : 1,
LoadedBehavior = MediaState.Manual,
UnloadedBehavior = MediaState.Stop
};
video.MediaOpened += (s, e) =>
{
video.SpeedRatio = 1.0;
};
int loopCount = 0;
video.MediaEnded += (s, e) =>
{
loopCount++;
if (loopCount < visibleTime)
{
video.Position = TimeSpan.Zero;
video.Play();
}
else
{
canvas.Children.Remove(video);
}
};
MultimediaUtilities.SetStretch(video, stretch);
Canvas.SetTop(video, y - (height / 2));
Canvas.SetLeft(video, x - (width / 2));
Canvas.SetZIndex(video, layer);
await Task.Delay(delay);
canvas.Children.Add(video);
video.Play();