首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PictureBox.Handle in .Netstandard

PictureBox.Handle in .Netstandard
EN

Stack Overflow用户
提问于 2021-03-19 09:47:42
回答 1查看 325关注 0票数 1

我正在开发C# WPF MVVM应用程序。我需要捕获JPEG,预览Live。为此,我使用了希克维 ip摄像头。

查看源代码,我需要一个PictureBox.Handle来显示Live。这是我班上的netstandard2.0

代码语言:javascript
运行
复制
public void LivePreview(System.Windows.Forms.PictureBox picturebox1)
{
   // SiginIn the user
   SignInHik();
   // If m_lUserID  > 0 means that the user signed in successfully
   if (m_lUserID < 0)
     {
       iLastErr = CHCNetSDK.NET_DVR_GetLastError();
       // Failed to login and output the error code
       str = "Login failed, error code= " + iLastErr;
    
       return;
     }
     else
     {
       // taking all chanels number
       dwAChanTotalNum = (uint)DeviceInfo.byChanNum;
       dwDChanTotalNum = (uint)DeviceInfo.byIPChanNum + 256 * (uint)DeviceInfo.byHighDChanNum;
     if (dwDChanTotalNum > 0)
     {
         InfoIPChannel();
     }
     else
     {
       for (int i = 0; i < dwAChanTotalNum; i++)
       {
          ListAnalogChannel(i + 1, 1);
          iChannelNum[i] = i + (int)DeviceInfo.byStartChan;
       }
    
         //comboBoxView.SelectedItem = 1;
         // MessageBox.Show("This device has no IP channel!");
      }
    }
    
   if (m_bRecord)
   {
      iLastErr = CHCNetSDK.NET_DVR_GetLastError();
      str = "Please stop recording firstly!, error code= " + iLastErr; // Failed to login and output the error code
    
       return;
   }
    
   if (m_lRealHandle < 0)
   {
      CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
      //live view window
      lpPreviewInfo.hPlayWnd = picturebox1.Handle; // HERE IS THE PROBLEM!!!
      //the device channel number
     lpPreviewInfo.lChannel = iChannelNum[(int)iSelIndex];
     //the device channel number
     lpPreviewInfo.lChannel = iChannelNum[(int)iSelIndex];
     //Stream type: 0-main stream, 1-sub stream, 2-stream 3, 3-stream 4, and so on
     lpPreviewInfo.dwStreamType = 0;
     //Connection mode: 0- TCP mode, 1- UDP mode, 2- multicast mode, 3- RTP mode, 4-RTP/RTSP, 5-RSTP/HTTP
     lpPreviewInfo.dwLinkMode = 0;
     //0- non-blocking access, 1- blocking access
     lpPreviewInfo.bBlocked = true;
     //The maximum number of frames in the display buffer of the playback library
     lpPreviewInfo.dwDisplayBufNum = 15;
     //User data
    IntPtr pUser = IntPtr.Zero;
    
   m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, RealData, pUser);
    
      if (m_lRealHandle < 0)
        {
          iLastErr = CHCNetSDK.NET_DVR_GetLastError();
          //failed to start live view, and output the error code.
          str = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; 
          //DebugInfo(str);
          return;
        }
       else
       {
           //Preview is successful
           DebugInfo("NET_DVR_RealPlay_V40 succ!");
           btnPreview = "Stop View";
       }
    }
    else
    {
       //Stop live view 
       if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle))
       {
           iLastErr = CHCNetSDK.NET_DVR_GetLastError();
           str = "NET_DVR_StopRealPlay failed, error code= " + iLastErr;
           return;
      }
    
         m_lRealHandle = -1;
         // btnPreview.Text = "Live View";
         //picturebox1.Invalidate();//刷新窗口 refresh the window
      }
          return;
   }

lpPreviewInfo.hPlayWndIntPtr,我不知道在WPF中可以使用什么来显示Live。

我在我的类liblry中添加了System.Windows.Forms.dll来访问PictureBox,但是我得到了错误:

错误CS1705程序集'System.Windows.Forms‘与标识'System.Windows.Forms,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089’使用'System.ComponentModel.Primitives,Version=4.2.2.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a‘,后者的版本高于标识'System.ComponentModel.Primitives,Version=4.1.2.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a’的引用程序集'System.ComponentModel.Primitives‘。

看来我解决不了这个问题。

有什么例子/建议吗?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-22 03:26:19

.NET标准不包括WPF或WinForms,因此您的库应该针对.NET框架和/或.NET核心。然后,您只需向项目文件中添加一个UseWindowsForms标记,所有引用都将被正确解析。不需要手动添加引用。

WPF控件没有窗口句柄,因此需要使用Windows控件(例如PictureBox)。要将其添加到WPF窗口,需要将其包装到WindowsFormsHost中。

代码语言:javascript
运行
复制
<Window x:Class="HostingWfInWpfWithXaml.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms">
    <Grid>    
        <WindowsFormsHost>
            <forms:PictureBox x:Name="picturebox1"/>
        </WindowsFormsHost>    
    </Grid>
</Window>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66705863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档