简体   繁体   English

网络摄像头预览中的图像引发通用GDI +异常

[英]Image from webcam preview throws generic GDI+ exception

I'm making a custom webcam user control. 我正在制作自定义网络摄像头用户控件。

I use Microsoft Expression Encoder, and set a PreviewWindow on a panel inside the control. 我使用Microsoft Expression Encoder,并在控件内部的面板上设置了PreviewWindow。

All's fine, except that when I try to grab the image, I get an exception: 很好,除了当我尝试获取图像时,我得到一个例外:

Generic GDI+ exception 通用GDI +例外

My first try was: 我的第一次尝试是:

using (var bmp = new Bitmap(p.Width, p.Width))
            {
                panel1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                bmp.Save(@"c:\test.png");
            }

Another waS: 另一个是:

using (Bitmap bitmap = new Bitmap(panelVideoPreview.Width, panelVideoPreview.Height))
          { 
              using (Graphics g = Graphics.FromImage(bitmap))
              {
                  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.jpg", DateTime.Now);
              bitmap.Save(strGrabFileName, ImageFormat.Jpeg);        

The problem is in writing the file. 问题在于写入文件。 There may not be enough space in c:\\ drive or you do not have permission to write to c:\\ drive(outside a folder). c:\\驱动器中可能没有足够的空间,或者您没有写c:\\驱动器(文件夹外部)的权限。 Try writing to AppData ,if you want to write to c:\\ drive,you need to acquire administrative privileges by using a custom manifest. 尝试写入AppData ,如果要写入c:\\ drive,则需要使用自定义清单获取管理权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM