我从网络摄像头捕获图像帧,但是当我将它们设置为WPF的图像控件时,它显示为空白。从网络摄像头以编程方式更新WPF图像控件输入
我使用返回位图的库,所以我将它转换为BitmapImage的,然后将我的形象控制到BitmapImage的通过调度来源:
void OnImageCaptured(Touchless.Vision.Contracts.IFrameSource frameSource, Touchless.Vision.Contracts.Frame frame, double fps)
{
image = frame.Image; // This is a class variable of type System.Drawing.Bitmap
Dispatcher.Invoke(new Action(UpdatePicture));
}
private void UpdatePicture()
{
imageControl.Source = null;
imageControl.Source = BitmapToBitmapImage(image);
}
private BitmapImage BitmapToBitmapImage(Bitmap bitmap)
{
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Png);
ms.Position = 0;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
return bi;
}
}
我的图像控制的XAML声明是关于尽可能通用:
<Image x:Name="imageControl" HorizontalAlignment="Left" Height="100" Margin="94,50,0,0" VerticalAlignment="Top" Width="100"/>
Image控件中没有显示任何内容 - 没有运行时错误。我究竟做错了什么?
非常感谢您的帮助!
这个工作。非常感谢你! – 2013-03-06 19:51:04