ScreenToGif.Webcam.DirectX.CaptureWebcam.BufferCB C# (CSharp) Method

BufferCB() public method

public BufferCB ( double SampleTime, IntPtr pBuffer, int BufferLen ) : int
SampleTime double
pBuffer System.IntPtr
BufferLen int
return int
        public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
        {
            if (CaptureFrameEvent == null) return 1;

            int width = _videoInfoHeader.BmiHeader.Width; //TODO: Make this a property.
            int height = _videoInfoHeader.BmiHeader.Height;

            int stride = width * 3;

            Marshal.Copy(pBuffer, _savedArray, 0, BufferLen);

            var handle = GCHandle.Alloc(_savedArray, GCHandleType.Pinned);
            var scan0 = (int)handle.AddrOfPinnedObject();
            //scan0 += (height - 1) * stride;
            scan0 += height * stride;

            var b = new Bitmap(width, height, -stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)scan0);
            handle.Free();

            CaptureFrameEvent(b);

            return 0;
        }