private void pCapture() { int bufSize = 0; IntPtr imgData; pSampleGrabber.GetCurrentBuffer(ref bufSize, IntPtr.Zero); if (bufSize < 1) { textBox1.Text = "Get(bufSize) Error"; //return ; } imgData = Marshal.AllocCoTaskMem(bufSize); pSampleGrabber.GetCurrentBuffer(ref bufSize, imgData); saveToJpg(imgData, bufSize, Video_Height, Video_Width); Marshal.FreeCoTaskMem(imgData); }
// Grab a snapshot of the most recent image played. // Returns A pointer to the raw pixel data. Caller must release this memory with // Marshal.FreeCoTaskMem when it is no longer needed. public IntPtr GetBitmap() { int hr; IntPtr ip = IntPtr.Zero; int iBuffSize = 0; // Read the buffer size hr = m_sampGrabber.GetCurrentBuffer(ref iBuffSize, ip); //DsError.ThrowExceptionForHR( hr ); //Debug.Assert(iBuffSize == m_ImageSize, "Unexpected buffer size"); // Allocate the buffer and read it ip = Marshal.AllocCoTaskMem(iBuffSize); hr = m_sampGrabber.GetCurrentBuffer(ref iBuffSize, ip); DsError.ThrowExceptionForHR(hr); return(ip); }