问题描述:

I have found a lot of similar posts about this, but none that are recent or actually address the issue. Hoping someone can help. Sorry if this is duplicate. I am not a WPF or xaml expert and have cobbled together code from various sources.

Scenario:-

  • Kiosk style app not for production, just for an exhibition
  • WFP app playing video as background on a grid using a mediaplayer being drawn with a brush
  • Kinect sensor to determine position of a person with state change events to change the source of the video based on the person's orientation (out of range, in range and looking at the sensor)
  • 3 Image controls (with PNG images with transparency as the source) over the top of the video which represent the persons current state. Images are collapsed or visible depending on the state

Everything is working as I am expecting it to, but there is a flicker (either solid white or black background) on the Image control when the Visibility of the images change when over the top of the video. If I hide the video as a test, there is no flicker, which suggests to me a rendering/drawing problem with the layering of the images and video. I started by borrowing from the Microsoft Kinect V2 samples and then building from there, but I don't think the Kinect itself would be causing the issue. All of the PC's I have been testing on exhibit this behaviour and are all recent powerful machines that have no problem running more complex applications.

Basic Video setup code (because I read about it somewhere, I didn't come up with it myself)

MediaPlayer mp = new MediaPlayer();

mp.ScrubbingEnabled = true;

mp.MediaEnded += MediaElement_MediaEnded;

mp.MediaOpened += MediaElement_MediaOpened;

VideoDrawing vd = new VideoDrawing();

vd.Player = mp;

vd.Rect = new Rect(0, 0, 1920, 1080);

DrawingBrush db = new DrawingBrush(vd);

grid.Background = db;

XAML

<Window x:Class="IgnoreYou.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Kinect 2 Face HD (.NET)"

Height="735" Width="770" Loaded="Window_Loaded" Closed="Window_Closing"

WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize"

WindowStartupLocation="CenterScreen"

Topmost="True"

MouseMove="Window_MouseMove">

<Grid Name="grid">

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">

<WrapPanel Margin="0,0,0,30">

<Image Name="noPerson" Source="images/noone.png" Stretch="None" >

</Image>

<Image Name="seenPerson" Source="images/can_you_see.png" Stretch="None" Visibility="Collapsed" >

</Image>

<Image Name="ignorePerson" Source="images/ignored.png" Stretch="None" Visibility="Collapsed" >

</Image>

</WrapPanel>

</StackPanel>

</Grid>

Switching the images example code (there are 3 variations):-

noPerson.Visibility = Visibility.Collapsed;

ignorePerson.Visibility = Visibility.Visible;

seenPerson.Visibility = Visibility.Collapsed;

I've looked various things

- Setting cachemode on images

- Doublebuffering doesn't seem to be thing anymore with modern WPF apps?

- Using opacity instead of visibility

- Stopping the video before the visibility is set (although probably doesn't matter without an actual delay timer?)

- Although the Kinect is firing at 30fps, the "person state change" events are only fired once and the switching code only fires once i.e. there are flags set to stop repeat entries

It doesn't do it all of the time, just most of the time.

Any help would be appreciated

Thanks,

Jarrod

相关阅读:
Top