我的目的是吧摄像头捕捉下来的视频帧每帧单独放在一个picturebox上.代码如下:
PictureBox pb = new PictureBox();
pb.Location = new System.Drawing.Point(x, 0);
x = x + 160;//这里的x是外部定义的一个int类型.用于吧picbox向后排
pb.Size = new System.Drawing.Size(160, 120);
pb.Image = (Bitmap)Frame.Image;//这里的Frame.Image就是从摄像头捕获下来的帧
pb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
panel1.Controls.Add(pb);//这里添加到一个panel上..
以上这些代码是放在一个timer上循环的
以上代码虽然可以运行但是每次显示了5帧画面左右(就是说添加了5个picbox吧?)就出错了.
错误提示Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
错误语句停在Application.Run(new Form1());上.希望高人能解答

解决方案 »

  1.   

    还有
    pb.Image = (Bitmap)Frame.Image;//这里的Frame.Image就是从摄像头捕获下来的帧
    这句可能有问题,“Frame.Image”是如何获取的,以及是否有主动释放操作等等。
      

  2.   

    是因为页面的缓冲不够大,你需要在Web.config中增大缓冲设置和超时时间,如下:<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        
      <system.web>
      
      <httpRuntime maxRequestLength="1000000"
             useFullyQualifiedRedirectUrl="false"
             executionTimeout="3600"/>
    ...如果还不行,把maxRequestLength和executionTimeout换成更大的数值。
      

  3.   

    PictureBox搞成数组的
    PictureBox[] pb = new PictureBox[要生成的个数];
    int i=0;
    循环
    {
       pb[i] = new PictureBox()
    }
      

  4.   

    内存溢出吧,对于稀缺资源要即时使用即时释放,但是尽管如此还是会很耗费,不如就用一个picbox,然后不停的取image来重绘这个picbox
      

  5.   

    Knight94(愚翁) 摄像头捕获的是320*240的
    至于Frame.Image是那里来的.其实frame就是一个PictureBox.然后取得image属性
    我用的是www.codeproject.com上某个例子.具体那个忘记了.调用的是DirectX.Capture和DShowNET两个装配件代码 ModCap.CaptureInformation.CaptureInfo.FrameCaptureComplete += RefreshImage;//初始化窗体的时候执行的       int x = 0;
            public void RefreshImage(System.Windows.Forms.PictureBox Frame)
            {
                string[] s;
                s = ModCap.CaptureInformation.PathVideo.Split('.');
                PictureBox pb = new PictureBox();
                pb.Location = new System.Drawing.Point(x, 0);
                x = x + 160;
                pb.Size = new System.Drawing.Size(160, 120);
                pb.Image = (Bitmap)Frame.Image;
                pb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                panel1.Controls.Add(pb);
                ModCap.CaptureInformation.CounterFrames += 1;
                pb.Refresh();            //string[] s;
                //s = ModCap.CaptureInformation.PathVideo.Split('.');
                //this.pcbFrame.Image = Frame.Image;
                ////this.pcbFrame.Image.Save(s[0] + ModCap.CaptureInformation.CounterFrames + ".png");
                //ModCap.CaptureInformation.CounterFrames += 1;
                //this.pcbFrame.Refresh();
            }ModCap基本上属于一个静态类.class ModCap
        {
            public struct Active
            {
                public Filter Camera;
                public Capture CaptureInfo;
                public CW ConfWindow;
                public int Counter;
                public int CounterFrames;
                public string PathVideo;
            }        static public Active CaptureInformation;
            static public Filters Dispositivos = new Filters();        static public void PrepareCam(string PathVideo)
            {
                string[] s = PathVideo.Split('.');
                ConfParamCam();
                CaptureInformation.CaptureInfo.Filename = s[0] + CaptureInformation.Counter + ".avi";
                CaptureInformation.Counter += 1;
                CaptureInformation.CaptureInfo.RenderPreview();
            }        static public void ConfParamCam()
            {
                string[] s;
                Size size;
                double Rate;
                CaptureInformation.CaptureInfo.Stop();
                // Change the compressor
                CaptureInformation.CaptureInfo.VideoCompressor = Dispositivos.VideoCompressors[CaptureInformation.ConfWindow.cmbCompress.Items.IndexOf(CaptureInformation.ConfWindow.cmbCompress.Text)];
                // Change the image size
                s = CaptureInformation.ConfWindow.cmbTam.Text.Split('x');
                size = new Size((int)Math.Round(Conversion.Val(s[0])), (int)Math.Round(Conversion.Val(s[1])));//(Conversion.Val(s[0]), Conversion.Val(s[1]));
                CaptureInformation.CaptureInfo.FrameSize = size;
                // Change the number of frames per second
                s = CaptureInformation.ConfWindow.cmbFPS.Text.Split(' ');
                Rate = Conversion.Val(s[0]);
                CaptureInformation.CaptureInfo.FrameRate = Rate;
            }
        }
    Yellow198267() .我尝试过在循环最后调用GC.Collect();来释放资源.没用.
    yuesongboy(可极) 你的方法少后试一下.不过我试过吧用timer的循环截取改成在同一个picbox显示就没有问题.看我上面注解掉的代码.tipboy() 逝世新要求较高.不能暂停啊..wagod(天使之恋)如果放在同一个picbox里面.那么我如果想删除其中的一些帧怎么办?
      

  6.   

    能否不用picturebox,你直接用Image来存取,
    至于图片的显示,你可以直接去画。这样你至少可以减少对picturebox的使用。
      

  7.   

    如果我直接用image画.那么如何保证事实性?每次有一个新的图像上去就吧原来的拆构掉.然后吧新的图像显示出来?图像长度每次增加.如果这样做.那么我如果想编辑其中的某个帧如何做?比如我想删除其中一个帧.
      

  8.   

    你的Image是存在一个list中,编辑的时候,可以判断当前点在哪个region,然后对应list中的值进行操作,
    例如删除操作:
    你可以先通过点,找到region,然后再找到相应的list中的值,然后从其中删除,最后重画panel即可。