【问题标题】:Directshow.net not displaying overlay image on videoDirectshow.net 不在视频上显示叠加图像
【发布时间】:2018-06-20 14:58:59
【问题描述】:

在我的 Directshow.net 应用程序中,我使用 BufferCB 在每一帧上绘制时间戳。时间戳显示在屏幕上和快照中,但在写入 AVI 文件时不显示。 我错过了什么?

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;
   }

【问题讨论】:

    标签: c# overlay video-capture directshow directshow.net


    【解决方案1】:

    使用BufferCB,您可以获得数据的副本,并且您的更改会对进一步的数据流产生影响。相比之下,SampleCB 会公开实际数据,并允许您在进一步发送之前更改有效负载。

    【讨论】:

    • 感谢您的快速回复,我不知道 BufferCB 和 SampleCB 之间的区别。不幸的是,这并没有解决问题。经过进一步检查,我注意到文本显示在几个框架上,但很少,以至于似乎没有框架有它。任何进一步的建议将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    相关资源
    最近更新 更多