2012-06-22 54 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); 

和調用此函數。