www.pudn.com > SOAVI2BMP_ACTIVEMOVIE.rar > Avi2Bmp.cpp, change:2007-05-09,size:2528b


// Avi2Bmp.cpp: implementation of the CAvi2Bmp class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "SOAVI2BMP.h" 
#include "Avi2Bmp.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CAvi2Bmp::CAvi2Bmp() 
{ 
	AVIFileInit();          // opens AVIFile library  
} 
 
CAvi2Bmp::~CAvi2Bmp() 
{ 
	AVIStreamGetFrameClose( m_pget ); 
	AVIFileRelease( m_pAVIFile );  // closes the file  
 
	AVIFileExit();          // releases AVIFile library 
} 
 
BOOL CAvi2Bmp::OpenAviFile(LPCTSTR lpszPathName) 
{ 
	HRESULT hr_open,hr_info,hr_stream;  
 
    hr_open = AVIFileOpen(&m_pAVIFile, lpszPathName, OF_SHARE_DENY_WRITE|OF_READ, 0L);  
    if (hr_open != 0) 
	{  
        return FALSE;  
    }  
 
	hr_info = AVIFileInfo(m_pAVIFile, &m_pfi, sizeof(AVIFILEINFO)); 
	if (hr_info != 0) 
	{  
        return FALSE;  
    }  
 
	hr_stream = AVIFileGetStream( m_pAVIFile, &m_pavi, streamtypeVIDEO, 0); 
	if (hr_stream != 0) 
	{  
        return FALSE;  
    }  
	return TRUE; 
} 
 
BOOL CAvi2Bmp::OpenFrame(int FrameNumber) 
{ 
	m_pget = AVIStreamGetFrameOpen(m_pavi, NULL); 
	ASSERT( m_pget ); 
	 
	m_lpbi = (LPBITMAPINFOHEADER )AVIStreamGetFrame( m_pget, FrameNumber ); 
	ASSERT( m_lpbi != NULL ); 
	 
	m_pData = (unsigned char *)m_lpbi + m_lpbi->biSize + m_lpbi->biClrUsed * sizeof(RGBQUAD); 
	ASSERT( m_pData != NULL ); 
 
	m_Height = m_lpbi->biHeight; 
	m_Width  = m_lpbi->biWidth; 
 
//----------------------------------------------------------------------------- 
//	将当前帧存为文件 
	FILE *f; 
	BITMAPFILEHEADER bf; 
	bf.bfType      = 0x4d42;        // 0x42 = "B" 0x4d = "M"  
    bf.bfOffBits   = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER);  
    bf.bfSize      = bf.bfOffBits+m_Width*m_Height*3;  
    bf.bfReserved1 = 0;  
    bf.bfReserved2 = 0;  
 
	f = fopen("sotemp.bmp", "wb"); 
	if( f==NULL ) 
		return FALSE; 
 
	fwrite( &bf, sizeof(BITMAPFILEHEADER), 1, f ); 
 
	//lpbi->biSizeImage是等于m_iWidth*m_iHeight*3的 
	fwrite( m_lpbi, sizeof(BITMAPINFOHEADER)+m_lpbi->biSizeImage, 1, f ); 
 
	fclose( f ); 
	 
	AfxMessageBox("sotemp.bmp created."); 
//----------------------------------------------------------------------------- 
 
	if( m_lpbi!=NULL && m_pData!=NULL ) 
		return TRUE; 
	else 
		return FALSE; 
	 
}