public static void AddFrame(Bitmap frameImage) { // Lock the bitmap BitmapData imageData = frameImage.LockBits(new Rectangle(0, 0, m_Width, m_Height), ImageLockMode.ReadOnly, frameImage.PixelFormat); // Copy and flip the frame IntPtr pSourceScanline = imageData.Scan0 + m_Stride * (m_Height - 1); IntPtr pDestinationScanline = m_FlippedFrameBuffer; IntPtr pStride = new IntPtr(m_Stride); for (int y = 0; y < m_Height; y++) { NM.memcpy(pDestinationScanline, pSourceScanline, pStride); pDestinationScanline += m_Stride; pSourceScanline -= m_Stride; } // Unlock the bitmap frameImage.UnlockBits(imageData);; // Write the frame to the stream if (NM.AVIStreamWrite(m_StreamCompressed, m_CurrentFrame, 1, m_FlippedFrameBuffer, m_Stride * m_Height, 0, IntPtr.Zero, IntPtr.Zero) != 0) { throw new Exception("Failed to add frame"); } m_CurrentFrame++; }