我有WCF服务捕捉摄像头图像并发送到客户端,它在我的WinForms应用程序中效果很好。我决定创建WPF客户端应用程序。WPF图片来源不从流加载
我有代码:
void timer1_Tick(object sender, EventArgs e)
{
counter++;
try
{
Stream imageStream = client.GetImage();
using (MemoryStream stream = new MemoryStream())
{
imageStream.CopyTo(stream);
int size = (int)stream.Length;
cam_img.Source = BitmapFrame.Create(stream,
BitmapCreateOptions.None,
BitmapCacheOption.OnLoad);
}
System.Diagnostics.Debug.WriteLine(counter);
}
catch (System.ServiceModel.CommunicationException ex)
{
if (ex.InnerException is System.ServiceModel.QuotaExceededException)
{
}
else
{
throw ex;
}
}
catch (System.Exception ex)
{
}
}
cam_img是图像控制。在调试器模式中,我看到该数据流包含数据,但每个滴答事件中的cam_img.source
为null
。
接下来的问题是,我必须实现propertychanged事件,使图像动态绑定?或者在每个计时器中分配到cam_img.source
刻度足以看到控制上的动态变化?
什么是'img_cam'? – terry
抱歉,每个滴答事件中cam_img.source都为null。它似乎有点不正确的bitmapfram.create,因为流包含数据 –
@ user3197850请回答问题 – csharpwinphonexaml