gpt4 book ai didi

c# - PictureBox.Handle Intptr 到图像或位图

转载 作者:行者123 更新时间:2023-11-30 18:26:06 25 4
gpt4 key购买 nike

我需要有关 HikVision IPCam 视频流的帮助。我搜索了 2 个洞周,但运气不佳。

我的问题是 IPCamm DLL 使用 PictureBox.Handle 将图像流式传输到图片框中。它工作得很好:

[DllImport("HCNetSDK.dll")]
public static extern int NET_DVR_RealPlay_V30(int lUserID, ref NET_DVR_CLIENTINFO lpClientInfo, RealDataCallBack_V30 fRealDataCallBack_V30, IntPtr pUser, bool bBlocked);

this.realDataCallBack = new RealDataCallBack_V30(RealDataCallback);
this.clientInfo.hPlayWnd = PictureBox.Handle;
this.clientInfo.lChannel = channel;
this.clientInfo.lLinkMode = 0;

this.playHandle = NET_DVR_RealPlay_V30(this.userID, ref this.clientInfo, realDataCallBack, IntPtr.Zero, true);

我的问题是我需要处理图像,但我无法将图像捕获为位图或图像,然后按我喜欢的方式显示它。

我尝试了 Bitmap.FromHbitmap(PictureBox.Handle),尝试了一些 MemoryMarshel 解决方案,但没有成功。

我现在获得它的唯一方法是从质量较低、帧数较低的回调函数中获取数据,...

最佳答案

此代码段将句柄中的数据绘制到位图中,然后设置图片框的图像。在旧系统上可能不需要 CopyFromScreen 行。

PictureBox.Image = CaptureControl(PictureBox.Handle, PictureBox.Width, PictureBox.Height);
// PictureBox.Image now contains the data that was drawn to it

[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
public Bitmap CaptureControl(IntPtr handle, int width, int height)
{
Bitmap controlBmp;
using (Graphics g1 = Graphics.FromHwnd(handle))
{
controlBmp = new Bitmap(width, height, g1);
using (Graphics g2 = Graphics.FromImage(controlBmp))
{
g2.CopyFromScreen(this.Location.X + PictureBox.Left, this.Location.Y + PictureBox.Top, 0, 0, PictureBox.Size);

IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();

BitBlt(dc2, 0, 0, width, height, handle, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
}
}

return controlBmp;
}

关于c# - PictureBox.Handle Intptr 到图像或位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29077052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com