我正在尝试PictureBox
从我插入的相机上绘制图像WindowsFormsHost
。代码很简单如下:
<Window x:Class="videoTEst.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="583" Width="1132"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
<StackPanel Background="LightBlue" Height="513" Width="1077">
<StackPanel HorizontalAlignment="Center" Width="450" Orientation="Horizontal">
<Button Name="ButtonOpen" Content="Load" Click="ButtonOpen_OnClick" />
<Button Name="ButtonLoadImage" Content="Load image" Click="ButtonLoadImage_OnClick" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<WindowsFormsHost Name="WinFormsHost" Height="440" Width="690" HorizontalAlignment="Left">
<wf:PictureBox x:Name="PictureBoxvideo" SizeMode="Normal" Paint="PictureBoxvideo_Paint"></wf:PictureBox>
</WindowsFormsHost>
<ListBox Name="ListBoxLog" />
</StackPanel>
</StackPanel>
我像这样从相机中绘画:
private void asyncVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Image temp = PictureBoxvideo.Image;
Bitmap bitmap = eventArgs.Frame;
PictureBoxvideo.Image = new Bitmap(bitmap);
if (temp != null) temp.Dispose();
bitmap.Dispose();
}
此代码完美运行。
但是当我将<Window>
标签更改为<UserControl>
(因为我希望它自己嵌入UserControl
)时,它不会绘画!
为什么不画在a上UserControl
?
为什么我不使用Image
WPF?
Image
线程使用确实令人困惑,每当我尝试在 上绘画时Image
,Bitmap
之前都已处理。