-1

In my Directshow.net app I am drawing a timestamp on each frame using the BufferCB. The timestamp is displayed on the screen and in snapshots but not when written to an AVI file. What am I missing?

int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) {
    int stride = 0;
    int scan0 = 0;
    Bitmap FrameShot = null;
    GCHandle handle;

    // Draw Time Stamp
    if (overlayBitmap != null & overlayEnabled) {
        // Create image to draw on camera frame shot
        Graphics g = Graphics.FromImage(overlayBitmap);
        g.Clear(Color.Transparent);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.TextRenderingHint = TextRenderingHint.AntiAlias;
        DateTime now = DateTime.Now;
        string format = "M/d/yyy HH:mm:ss.fff";
        g.DrawString(now.ToString(format), fontOverlay, textYellow, 4, SnapShotHeight - FontSize * 2);

        // Draw image on camera frame shot
        stride = SnapShotWidth * 3;
        FrameShot = new Bitmap(SnapShotWidth, SnapShotHeight, stride, PixelFormat.Format24bppRgb, pBuffer);
        Graphics g2 = Graphics.FromImage(FrameShot);
        g2.SmoothingMode = SmoothingMode.AntiAlias;
        overlayBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
        g2.DrawImage(overlayBitmap, 0, 0, overlayBitmap.Width, overlayBitmap.Height);

        g.Dispose();
        g2.Dispose();
        FrameShot.Dispose();
    }
    //Has a snapshot been requested?
    if (frameCaptured) {
        return 0;
    }
    frameCaptured = true;
    bufferedSize = BufferLen;

    stride = SnapShotWidth * 3;
    Marshal.Copy(pBuffer, savedArray, 0, BufferLen);

    handle = GCHandle.Alloc(savedArray, GCHandleType.Pinned);
    scan0 = (int)handle.AddrOfPinnedObject();
    scan0 += (SnapShotHeight - 1) * stride;
    FrameShot = new Bitmap(SnapShotWidth, SnapShotHeight, -stride, PixelFormat.Format24bppRgb, (IntPtr)scan0);
    handle.Free();

    // Return bitmap by an event
    FrameEvent2(FrameShot);
    return 0;
   }
Roman R.
  • 68,205
  • 6
  • 94
  • 158

1 Answers1

0

With BufferCB you have a copy of the data and your changes have on effect on further data streaming. SampleCB in contrast exposes the actual data and lets you change the payload before it is sent further.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thanks for your quick response, I did not know the difference between BufferCB and SampleCB. Unfortunately that did not salve the problem. Upon further examination I noticed that the text is displayed on a few frames but so few that it appears that no frames has it. Any further suggestions would be greatly appreciated. – Hans Mills Aug 01 '18 at 16:45