通过SDK捕获摄像机流,该摄像机流需要IntPtr到WPF中的窗口(没有空域问题)

问题描述 投票:0回答:1

我有一个用于IP摄像机的SDK,负责开始接收流的功能需要将IntPtr传递给Window,该窗口将用于显示流。在WPF中,我只能在while窗口上显示图像,因为只有窗口在WPF中具有Handle。我试图打开新窗口并将内容复制到主窗口中的某些控件中,但没有取得很大的成功。是否有任何选择,例如使虚拟IntPtr并以某种方式从中获取图像/流?

[DllImport("dhnetsdk.dll")]
    public static extern IntPtr CLIENT_StartRealPlay(IntPtr lLoginID, int nChannelID, IntPtr hWnd, EM_RealPlayType rType, fRealDataCallBackEx cbRealData, fRealPlayDisConnectCallBack cbDisconnect, IntPtr dwUser, uint dwWaitTime);
c# wpf xaml camera interop
1个回答
1
投票

您可以使用System.Windows.Media.Imaging.WriteableBitmap并将其IntPtr句柄传递给相机的SDK调用。

这里是一个例子:

private void VideoSampleReady(byte[] sample, uint width, uint height, int stride, WriteableBitmap wBmp, System.Windows.Controls.Image dst)
{
    if (sample != null && sample.Length > 0)
    {
        this.Dispatcher.BeginInvoke(new Action(() =>
        {
            if (wBmp == null || wBmp.Width != width || wBmp.Height != height)
            {
                wBmp = new WriteableBitmap(
                    (int)width,
                    (int)height,
                    96,
                    96,
                    PixelFormats.Bgr24,
                    null);

                dst.Source = wBmp;
            }

            // Reserve the back buffer for updates.
            wBmp.Lock();

            Marshal.Copy(sample, 0, wBmp.BackBuffer, sample.Length);

            // Specify the area of the bitmap that changed.
            wBmp.AddDirtyRect(new Int32Rect(0, 0, (int)width, (int)height));

            // Release the back buffer and make it available for display.
            wBmp.Unlock();
        }), System.Windows.Threading.DispatcherPriority.Normal);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.