// Callback method that receives a pointer to the sample buffer public int BufferCB(double sampleTime, IntPtr buffer, int bufferLen) { if (parent.NewFrame != null) { // create new image System.Drawing.Bitmap image = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); // lock bitmap data BitmapData imageData = image.LockBits( new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // copy image data int srcStride = imageData.Stride; int dstStride = imageData.Stride; unsafe { byte *dst = (byte *)imageData.Scan0.ToPointer() + dstStride * (Height - 1); byte *src = (byte *)buffer.ToPointer(); for (int y = 0; y < Height; y++) { Win32.memcpy(dst, src, srcStride); dst -= dstStride; src += srcStride; } } // unlock bitmap data image.UnlockBits(imageData); // notify parent parent.RaiseNewFrameEvent(image, DateTime.Now); // release the image image.Dispose(); } return(0); }