如何将bmp转化为avi?
如何将bmp转化为avi?
如何将一系列的bmp 变为 avi呢???
使用系统自带的 vfw32.lib 来制作...
AVIFileInit();
AVIFileOpen
AVIFileCreateStream
AVIMakeCompressedStream
AVIStreamSetFormat
AVIStreamWrite
AVIFileRelease
这是 avi制作的流程...对于具体函数的解释,可以参考msdn .......
你如果图方便不想了解太多...那么可以到
http://www.codeproject.com/bitmap/createmovie.asp
下载你需要的头文件..那么在使用时 会十分简单.....
在你的工程中加入了avifile.h和avifile.cpp后, 接着导入vfw32.lib (在vc6.0的目录 vc98/lib中)
然后在需要转换的地方添加如下代码:
HBITMAP bmp;
CAviFile avi;
bmp=(HBITMAP)::LoadImage(NULL,"c://a.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
avi.AppendNewFrame(bmp);
对于16,24,32位的都可以正常显示....如果是通过位图数据来显示avi ,那么可以调用
avi.AppendNewFrame(636,480,newBits,16);函数
如何显示8位的灰度图呢?
按如下步骤:
it took me 3 steps
1:
call appendnewframe with 8 rather than 24:
AppendNewFrame(width,height,p_imData,8);
instead of:
AppendNewFrame(width,height,p_imData,24);
2)
change the following function:
HRESULT CAviFile::AppendFrameFirstTime(int nWidth, int nHeight, LPVOID pBits,int nBitsPerPixel)
this function creates a BITMAPINFO:
/////////////////////////////
BITMAPINFO bmpInfo;
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biPlanes=1;
bmpInfo.bmiHeader.biWidth=nWidth;
bmpInfo.bmiHeader.biHeight=nHeight;
bmpInfo.bmiHeader.biCompression=BI_RGB;
bmpInfo.bmiHeader.biBitCount=nBitsPerPixel;
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*bmpInfo.bmiHeader.biHeight*bmpInfo.bmiHeader.biBitCount/8;
if(bmpInfo.bmiHeader.biHeight>nMaxHeight) nMaxHeight=bmpInfo.bmiHeader.biHeight;
if(bmpInfo.bmiHeader.biWidth>nMaxWidth) nMaxWidth=bmpInfo.bmiHeader.biWidth;
/////////////////////////////////
what you need is this:
////////////////////////////////////////
LPBITMAPINFO pbmi8;
//bitmap info
pbmi8 = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))];
//bitmap infoheader
pbmi8->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
pbmi8->bmiHeader.biWidth = nWidth;
pbmi8->bmiHeader.biHeight = nHeight;
pbmi8->bmiHeader.biPlanes = 1;
pbmi8->bmiHeader.biBitCount = 8; // bits per pixel
pbmi8->bmiHeader.biCompression = BI_RGB; //uncompressed format
pbmi8->bmiHeader.biSizeImage = 0; // can be 0 for BI_RGB bitmaps
pbmi8->bmiHeader.biXPelsPerMeter = 0;
pbmi8->bmiHeader.biYPelsPerMeter = 0;
pbmi8->bmiHeader.biClrUsed = 256;
pbmi8->bmiHeader.biClrImportant = 0;
//color table
for ( i = 0 ; i < 256 ; ++i )
{
//8-bits grayscale
pbmi8->bmiColors[i].rgbBlue = pbmi8->bmiColors[i].rgbGreen = pbmi8->bmiColors[i].rgbRed = i;
pbmi8->bmiColors[i].rgbReserved = 0;
}
//////////////////////////////////////////
(this code could be done better, but, as i mentiond, I'm not an expert)
3)
No, instead of using BITMAPINFO bmpInfo, You use LPBITMAPINFO pbmi8.
Only one time in your code, this bmpInfo is used:
/////////////////////////////
if(FAILED(AVIStreamSetFormat(m_pAviCompressedStream,0,(LPVOID)&bmpInfo,bmpInfo.bmiHeader.biSize)))
///////////////////////////
replace this line with:
////////////////////////////////
if(FAILED(AVIStreamSetFormat(m_pAviCompressedStream,0,(LPVOID)pbmi8,sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD)))))