public bool CaptureOneFrameAsync() { int fieldNumber = -1; var errorCode = OfficalApi.GetSnappingNumber(_cardHandle, ref fieldNumber); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡采集图像失败"); } if (fieldNumber < 0) { return(false); } int frameNumber = fieldNumber / 2 - 1; if (frameNumber == -1) { frameNumber = AsyncFramesCount - 1; } //Trace.WriteLine(DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss:fff") + " " + frameNumber); errorCode = OfficalApi.StaticMemLock(frameNumber * FrameBufferSize, FrameBufferSize, ref _staticMemoryHandle, ref _staticMemoryPointer); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡锁定图像失败"); } //传输到缓冲区 var sourcePtr = (byte *)_staticMemoryPointer.ToPointer(); var targetPtr = (byte *)CaptureFrameBuffer.ToPointer(); for (int i = 0; i < FrameBufferSize; i++) { *targetPtr++ = *sourcePtr++; } errorCode = OfficalApi.StaticMemUnlock(_staticMemoryHandle); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡解锁图像失败"); } return(true); }
/// <summary> /// 采集一帧 /// </summary> public bool CaptureOneFrameSync() { //采集图像 ErrorCode errorCode = OfficalApi.CaptureSync(_cardHandle, 0, 0, true, 1); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡采集图像失败"); } errorCode = OfficalApi.StaticMemLock(0, FrameBufferSize, ref _staticMemoryHandle, ref _staticMemoryPointer); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡锁定图像失败"); } //传输到缓冲区 var sourcePtr = (byte *)_staticMemoryPointer.ToPointer(); var targetPtr = (byte *)CaptureFrameBuffer.ToPointer(); for (int i = 0; i < FrameBufferSize; i++) { *targetPtr++ = *sourcePtr++; } errorCode = OfficalApi.StaticMemUnlock(_staticMemoryHandle); if (errorCode != ErrorCode.CG_OK) { return(false); //throw gcnew InvalidOperationException("采集卡解锁图像失败"); } return(true); }