// ------------------------------------------------------------------------------------------ // 从已经打开的序列文件中读出一个帧的数据 // ------------------------------------------------------------------------------------------ public bool ReadRawFrameDataFromFile(ref ggFrame_struct FrameInfoBuff, ref byte[] FrameRawBuff, ref byte[] FrameImageBuff, ref string sErrString) { uint dwlen, dwsize, dwcpsize; byte[] Datatmp; IntPtr buffer = Marshal.AllocHGlobal(1); bool bResult = false; try { dwlen = ggData.m_ggheader.cbsize_frame; Datatmp = br.ReadBytes((int)dwlen); if (Datatmp.Length == dwlen) { dwcpsize = (uint)Datatmp.Length; dwcpsize = dwcpsize < dwlen ? dwcpsize : dwlen; //lpdata->m_lpframeinfo = (LPRAWFRAME_INFO)lpdata->m_lpframedata; //CopyMemory(lpframeinfo, lpdata->m_lpframedata, sizeof(RAWFRAME_INFO)); int size = Marshal.SizeOf(typeof(ggFrame_struct)); Marshal.FreeHGlobal(buffer); // 释放以前分配的空间 buffer = Marshal.AllocHGlobal(size); // 重新分配 Marshal.Copy(Datatmp, 0, buffer, size); FrameInfoBuff = (ggFrame_struct)Marshal.PtrToStructure(buffer, typeof(ggFrame_struct)); if (FrameInfoBuff.cb_size >= size) { FrameRawBuff = new byte[FrameInfoBuff.rawdatasize]; Array.Copy(Datatmp, FrameInfoBuff.rawdataoffset, FrameRawBuff, 0, FrameInfoBuff.rawdatasize); //FrameImageBuff = new byte[FrameInfoBuff.videoimagesize]; //Array.Copy(Datatmp, FrameInfoBuff.imageoffset, FrameImageBuff, 0, FrameInfoBuff.videoimagesize); } else { FrameImageBuff = null; } sErrString = "成功"; bResult = true; } else { sErrString = "数据帧长度错误"; bResult = false; } } catch (Exception ex) { sErrString = "读帧数据错误(" + ex.Message + ")"; bResult = false; } finally { Marshal.FreeHGlobal(buffer); } return(bResult); }
public bool ReadFramDataFromMemo(int iFrameID, ref ggFrame_struct FrameInfoBuff, ref byte[] FrameRawBuff, ref byte[] FrameImageBuff, ref string sErrString) { bool bResult = false; IntPtr buffer = Marshal.AllocHGlobal(1); if (ggData.m_szFileName == "") // 还没关联gg文件 { sErrString = "尚未打开相关文件。"; return(bResult); } if (ggData.numberof_frames <= 0) { FrameInfoBuff = new ggFrame_struct(); // 没有数据 FrameRawBuff = null; return(bResult); } try { int size = Marshal.SizeOf(typeof(ggFrame_struct)); Marshal.FreeHGlobal(buffer); // 释放以前分配的空间 buffer = Marshal.AllocHGlobal(size); // 重新分配 Marshal.Copy(ggAllFrameInfo, iFrameID * size, buffer, size); FrameInfoBuff = (ggFrame_struct)Marshal.PtrToStructure(buffer, typeof(ggFrame_struct)); Array.Copy(ggAllRawData, iFrameID * ggData.m_sizeofrawdata, FrameRawBuff, 0, ggData.m_sizeofrawdata); bResult = true; } catch (Exception ex) { sErrString = "读取记录数据失败: " + ex.Message; } finally { Marshal.FreeHGlobal(buffer); } return(bResult); }