//int i = 0; void mjpegSource_NewFrame(object sender, CameraEventArgs e) { bmp = (Bitmap)e.Bitmap.Clone(); Graphics g = this.CreateGraphics(); Rectangle rc = this.ClientRectangle; g.DrawImage(bmp, rc.X + 1, rc.Y + 1, rc.Width - 2, rc.Height - 2); //Tiger.Video.VFW.AVIWriter aw = new Tiger.Video.VFW.AVIWriter(); //aw.Codec = "Divx Codec 4.12"; //aw.Open(@"e:/sp.avi", 704, 576); //aw.FrameRate = 15; aw.AddFrame(bmp); //aw.Close(); //System.IO.FileStream fs = new System.IO.FileStream(@"E:\sp.mjpeg", System.IO.FileMode.OpenOrCreate); //fs.Seek(i * 2000, System.IO.SeekOrigin.Begin);//18932 //bmp.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); ////bmp.SaveAdd(System.Drawing.Imaging.FrameDimension. ////fs.Write(buffer, start, stop - start); //fs.Close(); //i = i + 1; }
Bitmap bmp; //=new Bitmap(width, height); /// <summary> /// 录像处理 /// </summary> /// <param name="bmp1"></param> private void VideoLx(Image bmp1) { if (video) { try { lock (bmp1) { bmp = (Bitmap)bmp1.Clone(); } DateTime dt1; TimeSpan sp; Graphics g; switch (way) { case LxWay.Motion4Inter: //间隔时间检测运动,运动则记录 dt1 = System.DateTime.Now; sp = dt1.Subtract(dt); if (sp.TotalMilliseconds >= interTime) { if (motionDetecotor != null) { if (motionDetecotor.ProcessFrame1(bmp)) { aw.AddFrame(bmp); motionStstus = true; } } dt = dt1; } else { motionStstus = false; } //运动则记录 if (motionStstus) { aw.AddFrame(bmp); //g = Graphics.FromImage(bmp); //g.DrawString("录像中", new Font("宋体", 60), Brushes.Red, new PointF(20, 150)); } break; case LxWay.Motion4: if (motionDetecotor != null) { if (motionDetecotor.ProcessFrame1(bmp)) { aw.AddFrame(bmp); // g = Graphics.FromImage(bmp); // g.DrawString("录像中", new Font("宋体", 60), Brushes.Red, new PointF(20, 150)); } } break; case LxWay.TimeInter: dt1 = System.DateTime.Now; sp = dt1.Subtract(dt); if (Math.Abs(sp.TotalMilliseconds) >= interTime) { aw.AddFrame(bmp); //g = Graphics.FromImage(bmp); // g.DrawString("录像中", new Font("宋体", 60), Brushes.Red, new PointF(20, 150)); dt = dt1; } break; case LxWay.Always: aw.AddFrame(bmp); // g = Graphics.FromImage(bmp); // g.DrawString("录像中", new Font("宋体", 60), Brushes.Red, new PointF(20, 150)); break; } } catch { } } }