2012-06-22 24 views
0

使用directshow.net我可以能够录制视频和记录我在做文本覆盖为了这个,我配置的样本采集和buffercb方法我工作的框架这里是代码..文字叠加问题?

int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) 
    { 
     Graphics g; 
     String s; 
     float sLeft; 
     float sTop; 
     SizeF d; 

     g = Graphics.FromImage(bitmapOverlay); 
     g.Clear(System.Drawing.Color.Transparent); 
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 

     // Prepare to put the specified string on the image 
     g.DrawRectangle(System.Drawing.Pens.Transparent, 0, 0, 240 - 1, 176 - 1); 
     g.DrawRectangle(System.Drawing.Pens.Transparent, 1, 1, 240 - 3, 176 - 3); 

     d = g.MeasureString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay); 

     sLeft = (240 - d.Width)/2; 
     sTop = (176 - d.Height)/2; 

     g.DrawString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay, System.Drawing.Brushes.Black, 
      sLeft, sTop, System.Drawing.StringFormat.GenericTypographic); 

     // need to flip the bitmap so it's the same orientation as the 
     // video buffer 
     bitmapOverlay.RotateFlip(RotateFlipType.RotateNoneFlipY); 

     // create and copy the video's buffer image to a bitmap 
     Bitmap v; 
     v = new Bitmap(240, 176, 1056, 
      PixelFormat.Format24bppRgb, pBuffer); 
     g = Graphics.FromImage(v); 
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
     // draw the overlay bitmap over the video's bitmap 
     g.DrawImage(bitmapOverlay, 0, 0, bitmapOverlay.Width, bitmapOverlay.Height); 
     // dispose of the various objects 
     g.Dispose(); 
     v.Dispose(); 
     // Increment frame number. Done this way, frame are zero indexed. 
     m_Count++; 
     return 0; 
    } 

我的问题是,当我开始程序时,它显示我在预览窗口中的文本覆盖,但是当我打开记录文件覆盖文字不会继续..我想我缺少一些帧..在一些帧覆盖是他们,但它不会继续。 。轻弹。 任何人都可以帮忙吗?

回答

0

好的我得到了问题!

在上面的代码

,BufferCB时间太长的时间来处理所述当前视频frame.its像设帧A仍然在中间处理之前处理完整的帧B来到英寸

所以在BufferCB最小化处理我已经除去media.run被调用之前的其中位图图像被设置 这行代码我放入功能

g = Graphics.FromImage(bitmapOverlay); 
    g.Clear(System.Drawing.Color.Transparent); 
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 

    // Prepare to put the specified string on the image 
    g.DrawRectangle(System.Drawing.Pens.Transparent, 0, 0, 240 - 1, 176 - 1); 
    g.DrawRectangle(System.Drawing.Pens.Transparent, 1, 1, 240 - 3, 176 - 3); 

    d = g.MeasureString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay); 

    sLeft = (240 - d.Width)/2; 
    sTop = (176 - d.Height)/2; 

    g.DrawString(m_String + "\n" + DateTime.Now.ToString("G"), fontOverlay, System.Drawing.Brushes.Black, 
     sLeft, sTop, System.Drawing.StringFormat.GenericTypographic); 

    // need to flip the bitmap so it's the same orientation as the 
    // video buffer 
    bitmapOverlay.RotateFlip(RotateFlipType.RotateNoneFlipY); 

和调用此函数。