我有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