如何使用图像控件显示视频流中的图像

时间:2017-05-10 16:48:12

标签: c# wpf image video

我是c#begginer。我使用wpf图像控件来显示来自我相机的图像。它通常在winform pictureBox中工作,但在WPF图像控制中不起作用。这一切都是空白的!我确信数据流存在。

icImagingControl1是我的相机SDK的控件。 它可以以多种形式返回图像数据。像Intptr,Byte,Bitmap。 我想从内存中加载图像控制数据。 每次相机拍摄时都会触发该功能。 这是我的代码。

private void icImagingControl1_ImageAvailable(object sender, XXX.Imaging.ICImagingControl.ImageAvailableEventArgs e)
        {                
            XXX.Imaging.ImageBuffer CurrentBuffer = null;
            CurrentBuffer = icImagingControl1.ImageBuffers[e.bufferIndex];
            try
            {
                using (MemoryStream memory = new MemoryStream())
                {
                    CurrentBuffer.Bitmap.Save(memory, ImageFormat.Bmp);
                    memory.Position = 0;
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memory;
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                    image1.Source = bitmapImage;   
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }


        }

希望有人能帮助我。

0 个答案:

没有答案
相关问题