int OpenIrVideo::SendImageData(THPARAM *param, int sourceDes,CFile& fs) //发送镜像数据
{
g_imageBuffSize=_IR_320_BUFF_SIZE_;
AVIFileInit(); //初始化AVI文件
PAVIFILE avi;
int res=AVIFileOpen(&avi, m_AVIName, OF_READ, NULL); //打开avi文件,m_AVIName是avi路径名
if (res!=AVIERR_OK)
{
//an error occures
if (avi!=NULL)
AVIFileRelease(avi);
}
AVIFILEINFO avi_info;
AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO));
PAVISTREAM pStream;
res=AVIFileGetStream(avi, &pStream, streamtypeVIDEO /*video stream*/,
0 /*first stream*/);
if (res!=AVIERR_OK)
{
if (pStream!=NULL)
AVIStreamRelease(pStream);
AVIFileExit();
}
int iNumFrames;
int iFirstFrame;
iFirstFrame=AVIStreamStart(pStream); //获取起始帧
if (iFirstFrame==-1)
{
//Error getteing the frame inside the stream
if (pStream!=NULL)
AVIStreamRelease(pStream);
AVIFileExit();
}
iNumFrames=AVIStreamLength(pStream); //获取帧长度
if (iNumFrames==-1)
{
//Error getteing the number of frames inside the stream
if (pStream!=NULL)
AVIStreamRelease(pStream);
AVIFileExit();
}
PGETFRAME pFrame;
pFrame=AVIStreamGetFrameOpen(pStream,
NULL/*(BITMAPINFOHEADER*) AVIGETFRAMEF_BESTDISPLAYFMT*/ /*&bih*/);
int index=0;
BYTE* pDIB;
for (int i=iFirstFrame; i<iNumFrames; i++)
{
index= i-iFirstFrame;
pDIB = (BYTE*)AVIStreamGetFrame(pFrame, index); //获取每帧的数据流
SynSendData(param,4,pDIB,g_imageBuffSize);
m_Bitmap = BufferToBitmap(pDIB); //将内存中的BMP文件内容转换到HBITMAP
HBITMAP OldBitmap;
CWnd* pWnd = CWnd::FromHandle(m_winPicHandle);;
CDC* pDC = pWnd->GetDC();
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
OldBitmap = (HBITMAP)MemDC.SelectObject(m_Bitmap);
CRect rect;
pWnd->GetClientRect(&rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(OldBitmap);
MemDC.DeleteDC();
pWnd->ReleaseDC(pDC);
Sleep(100);
if(i == iNumFrames-1)
{
i = 0;
}
}
return 1;
}