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