我的目的是吧摄像头捕捉下来的视频帧每帧单独放在一个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());上.希望高人能解答
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());上.希望高人能解答
解决方案 »
- AE System._ComObject 编译
- 菜鸟求教关于继承
- 有用C#搞托管DirectX开发的朋友么?
- 有个C#写的网络程序,在一般机上cpu占用只有一两个点.很少超过10%,但在极个别客户机上cpu占用100%?多线程的GetResponse()去按顺序排队过
- 奇怪问题,谁遇到过,请教一下~~~~~~~~
- 通过SMTP的方式用yahoo.cn的邮箱发送邮件的问题,很怪,高分(100),
- 在propertygrid控件中怎么不显示属性的注释?
- 如何抓取需要用户名和密码的网页??
- socket发送数据问题
- 为什么不能删除Access纪录?
- C#的MID如何得到子窗体相对于父窗体的位置?
- C#中对ACCESS数据库的条件查询
pb.Image = (Bitmap)Frame.Image;//这里的Frame.Image就是从摄像头捕获下来的帧
这句可能有问题,“Frame.Image”是如何获取的,以及是否有主动释放操作等等。
<configuration>
<system.web>
<httpRuntime maxRequestLength="1000000"
useFullyQualifiedRedirectUrl="false"
executionTimeout="3600"/>
...如果还不行,把maxRequestLength和executionTimeout换成更大的数值。
PictureBox[] pb = new PictureBox[要生成的个数];
int i=0;
循环
{
pb[i] = new PictureBox()
}
至于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里面.那么我如果想删除其中的一些帧怎么办?
至于图片的显示,你可以直接去画。这样你至少可以减少对picturebox的使用。
例如删除操作:
你可以先通过点,找到region,然后再找到相应的list中的值,然后从其中删除,最后重画panel即可。