使用表达式编码的 WPF 网络摄像头捕获

发布于 2024-12-11 17:58:59 字数 538 浏览 0 评论 0原文

我正在制作一个将在内置两个网络摄像头的平板电脑设备上运行的应用程序。要求之一是能够捕获图像并保存它们。

到目前为止,我已经能够使用此代码获取网络摄像头输出的预览,

Dim Job As New LiveJob
Dim source As LiveDeviceSource
source = Job.AddDeviceSource(EncoderDevices.FindDevices(EncoderDeviceType.Video).Item(0), Nothing)

source.PreviewWindow = New PreviewWindow(New HandleRef(Me.panPreview, Me.panPreview.Handle))

Job.ActivateSource(source)

这会在托管 winforms 面板中显示预览。问题是如何从该流中捕获图像并返回新的图像对象以供以后处理?

我尝试使用 RenderTargetBitmap 捕获 winforms 主机,但只返回一个黑色矩形,它不会让我渲染 winforms 面板。

I’m making an application that will run on a tablet device that has two webcams built in. One of the requirements is to be able to capture images and save them.

So far I have been able to get the preview of the webcam’s output using this code

Dim Job As New LiveJob
Dim source As LiveDeviceSource
source = Job.AddDeviceSource(EncoderDevices.FindDevices(EncoderDeviceType.Video).Item(0), Nothing)

source.PreviewWindow = New PreviewWindow(New HandleRef(Me.panPreview, Me.panPreview.Handle))

Job.ActivateSource(source)

This displays the preview in a hosted winforms panel. The question is how do I capture an image from this stream and return a new image object for later processing?

I have tried capturing the winforms host using RenderTargetBitmap but just returns a black rectangle and it wont let me render the winforms panel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滥情空心 2024-12-18 17:58:59

刚刚在代码项目中找到了这块宝石。这是代码。这里的 panelVideoPreview 是您的预览,即 panPreview 窗口。希望这有帮助。

private void cmdGrabImage_Click(object sender, EventArgs e)        
{
// Create a Bitmap of the same dimension of panelVideoPreview (Width x Height)
    using (Bitmap bitmap = new Bitmap(panelVideoPreview.Width, panelVideoPreview.Height))
    { 
        using (Graphics g = Graphics.FromImage(bitmap))
        {
            // Get the paramters to call g.CopyFromScreen and get the image
            Rectangle rectanglePanelVideoPreview = panelVideoPreview.Bounds;
            Point sourcePoints = panelVideoPreview.PointToScreen(new Point(panelVideoPreview.ClientRectangle.X, panelVideoPreview.ClientRectangle.Y));
            g.CopyFromScreen(sourcePoints, Point.Empty, rectanglePanelVideoPreview.Size); 
        }
        string strGrabFileName = String.Format("C:\\Snapshot_{0:yyyyMMdd_hhmmss}.jpg", DateTime.Now);
        toolStripStatusLabel1.Text = strGrabFileName;
        bitmap.Save(strGrabFileName, System.Drawing.Imaging.ImageFormat.Jpeg);                
    }
}

Just found this piece of gem on code project. Here goes the code. Here panelVideoPreview is your preview i.e. panPreview window. hope this helps.

private void cmdGrabImage_Click(object sender, EventArgs e)        
{
// Create a Bitmap of the same dimension of panelVideoPreview (Width x Height)
    using (Bitmap bitmap = new Bitmap(panelVideoPreview.Width, panelVideoPreview.Height))
    { 
        using (Graphics g = Graphics.FromImage(bitmap))
        {
            // Get the paramters to call g.CopyFromScreen and get the image
            Rectangle rectanglePanelVideoPreview = panelVideoPreview.Bounds;
            Point sourcePoints = panelVideoPreview.PointToScreen(new Point(panelVideoPreview.ClientRectangle.X, panelVideoPreview.ClientRectangle.Y));
            g.CopyFromScreen(sourcePoints, Point.Empty, rectanglePanelVideoPreview.Size); 
        }
        string strGrabFileName = String.Format("C:\\Snapshot_{0:yyyyMMdd_hhmmss}.jpg", DateTime.Now);
        toolStripStatusLabel1.Text = strGrabFileName;
        bitmap.Save(strGrabFileName, System.Drawing.Imaging.ImageFormat.Jpeg);                
    }
}
枯寂 2024-12-18 17:58:59

如果您想要捕获的窗口上方有一个窗口,那么捕获的将是窗口上方的图像,或者如果您最小化窗口,则同样会捕获坐标的屏幕截图。此方法是使用坐标捕获屏幕。

流媒体的捕获图像如何?

If you have a window over the window you want to capture the capture will be an image of the over window or if you minimize the window occurs the same, you'll capture a screenshot of the coordenates. This method is a capture of screen with coordenates.

How it would be the capture image of the streaming?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文