续问??? "如何将一组BMP图片转换为AVI文件"?

fengzhihun 2005-05-04 10:23:29
我使用http://www.codeguru.com/Cpp/G-M/multimedia/article.php/c1571/中的代码,

CAVIFile avi("test.avi");
for (int i=0; i<=20; i++)
{
CBitmap bmp;
... // fill with data ??此处我应该如何添加代码呢?(我有一个指向图像的指针pBMPBuffer)
avi.AddFrame(bmp);
}

但是添加图像数据后,产生的avi文件却是黑屏?

////////////////////////////////////////////////////////////
//于是,我对上述部分作了修改添加
////////////////////////////////////////////////////////////
CAVIFile avi("test.avi");
for (int i=0; i<=20; i++)
{
HBITMAP HBmp;

HBmp= CreateBitmap( m_CX, m_CY, 1, 8*m_BYTES, (void *)pBMPBuffer );
//m_CX市位图的宽, m_CY位图的高,pBMPBuffer是指向二进制位图色彩数据的指针

avi.AddFrame(HBmp);
}

我使用的是位图的句柄,并将CAVIFile::AddFrame(HBITMAP HBmp)的参数类型设定为HBITMAP,

并且修改static HANDLE MakeDib( BITMAP bitmap, UINT bits );
为 static HANDLE MakeDib( HBITMAP hbitmap, UINT bits );

可是仍然为黑屏,我应该如何修改呢?
...全文
170 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcmute 2005-05-04
  • 打赏
  • 举报
回复
The CreateBitmap function can be used to create color bitmaps. However, for performance reasons applications should use CreateBitmap to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps.
Stefine 2005-05-04
  • 打赏
  • 举报
回复
不懂,来学习的
vcmute 2005-05-04
  • 打赏
  • 举报
回复
http://www.codeguru.com/Cpp/G-M/multimedia/article.php/c1571/中的代码默认是256色的

在尽量不修改其框架的情况下,做了一下改动
1.主要是加入lpByte,既然本身是DIB,就不用再转DDB后转入DIB
bool CAVIFile::AddFrame(HBITMAP bmp,LPBYTE lpByte/*=NULL*/ )
{
HRESULT hr;
char szMessage[BUFSIZE];

if (!bOK)
return false;
LPBITMAPINFOHEADER alpbi = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(bmp, lpByte ));
if (alpbi == NULL)
return false;
2.将MakeDib的第二个参数也改成lpByte
static HANDLE MakeDib( HBITMAP hbitmap,LPBYTE lpByte )
{
HANDLE hdib ;
HDC hdc ;
BITMAP bitmap ;
UINT wLineLen ;
DWORD dwSize ;
DWORD wColSize ;
LPBITMAPINFOHEADER lpbi ;
LPBYTE lpBits ;

GetObject(hbitmap,sizeof(BITMAP),&bitmap) ;
UINT bits = bitmap.bmBitsPixel;
//
// DWORD align the width of the DIB
// Figure out the size of the colour table
// Calculate the size of the DIB
//
wLineLen = (bitmap.bmWidth*bits+31)/32 * 4;
wColSize = sizeof(RGBQUAD)*((bits <= 8) ? 1<<bits : 0);
dwSize = sizeof(BITMAPINFOHEADER) + wColSize +
(DWORD)(UINT)wLineLen*(DWORD)(UINT)bitmap.bmHeight;

//
// Allocate room for a DIB and set the LPBI fields
//
hdib = GlobalAlloc(GHND,dwSize);
if (!hdib)
return hdib ;

lpbi = (LPBITMAPINFOHEADER)GlobalLock(hdib) ;

lpbi->biSize = sizeof(BITMAPINFOHEADER) ;
lpbi->biWidth = bitmap.bmWidth ;
lpbi->biHeight = bitmap.bmHeight ;
lpbi->biPlanes = 1 ;
lpbi->biBitCount = (WORD) bits ;
lpbi->biCompression = BI_RGB ;
lpbi->biSizeImage = dwSize - sizeof(BITMAPINFOHEADER) - wColSize ;
lpbi->biXPelsPerMeter = 0 ;
lpbi->biYPelsPerMeter = 0 ;
lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;
lpbi->biClrImportant = 0 ;

//
// Get the bits from the bitmap and stuff them after the LPBI
//
lpBits = (LPBYTE)(lpbi+1)+wColSize ;
if(lpByte)
{
memcpy(lpBits,lpByte,lpbi->biSizeImage);
}
else
{
hdc = CreateCompatibleDC(NULL) ;

GetDIBits(hdc,hbitmap,0,bitmap.bmHeight,lpBits,(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);

// Fix this if GetDIBits messed it up....
lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;

DeleteDC(hdc) ;
}
GlobalUnlock(hdib);

return hdib ;
}
调用方法
HBITMAP HBmp;

HBmp= CreateBitmap( m_CX, m_CY, 1, 8*m_BYTES, NULL);
//m_CX市位图的宽, m_CY位图的高,pBMPBuffer是指向二进制位图色彩数据的指针

avi.AddFrame(HBmp, pBMPBuffer );

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧