/// <summary> /// Decode image stored in the buffer /// </summary> /// <param name="bufMat">The buffer</param> /// <param name="loadType">The image loading type</param> /// <returns>A pointer to the Image decoded.</returns> public static IntPtr cvDecodeImage(byte[] bufMat, CvEnum.LOAD_IMAGE_TYPE loadType) { GCHandle handle = GCHandle.Alloc(bufMat, GCHandleType.Pinned); try { using (Matrix <byte> mat = new Matrix <byte>(bufMat.Length, 1, 1, handle.AddrOfPinnedObject(), bufMat.Length)) { #region set the continute flag for the mat int CV_MAT_CONT_FLAG = 1 << 14; int type = Marshal.ReadInt32(mat.Ptr, MCvMatConstants.TypeOffset); Marshal.WriteInt32(mat.Ptr, MCvMatConstants.TypeOffset, type | CV_MAT_CONT_FLAG); #endregion return(cvDecodeImage(mat, loadType)); } } finally { handle.Free(); } }
public static extern IntPtr cvLoadImage( [MarshalAs(_stringMarshalType)] String filename, CvEnum.LOAD_IMAGE_TYPE loadType);
public static extern IntPtr cvDecodeImage(IntPtr bufMat, CvEnum.LOAD_IMAGE_TYPE loadType);