(thinkvd开发日志)在开发swf to video,保存bmp图时,刚好图象上下颠倒, 以前用了一个简单算法把图象数据倒过来,
在网上查了一下,据说有一个标志位,反复看了BITMAPFILEHEADER, BITMAPINFOHEADER结构,也没有发现是哪个变量。
后来想了想,把高度值变成相反值,结果图象还真的变成正立的了。
也就是设置BITMAPINFOHEADER中的info.biHeight取反即可。
void SaveBitmapBuffer(char* lpsFileName)
{
if (m_pFrameBuffer == NULL)
return ;
int size = BMP_BIBIT_COUNT / 8 * m_nWidth * m_nHeight;
int fhsize = sizeof(BITMAPFILEHEADER);
int bisize = sizeof(BITMAPINFOHEADER);
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER info;
memset ( &bmfh, 0, sizeof ( BITMAPFILEHEADER ) );
memset ( &info, 0, sizeof ( BITMAPINFOHEADER ) );
// First we fill the file header with data
bmfh.bfType = 0x4d42; // 0x4d42 = 'BM'
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
bmfh.bfSize = sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + size;
bmfh.bfOffBits = 0x36; // (54) size of headers
info.biSize = sizeof ( BITMAPINFOHEADER );
info.biWidth = m_nWidth;
info.biHeight = -m_nHeight;
info.biPlanes = 1;
info.biBitCount = BMP_BIBIT_COUNT;
info.biCompression = BI_RGB;
info.biSizeImage = 0;
info.biXPelsPerMeter = 0x0ec4;
info.biYPelsPerMeter = 0x0ec4;
info.biClrUsed = 0;
info.biClrImportant = 0;
BYTE* pBitmapFlashBuffer = new BYTE[fhsize + bisize + size];
if (pBitmapFlashBuffer)
{
memcpy(pBitmapFlashBuffer, &bmfh, fhsize);
memcpy(pBitmapFlashBuffer + fhsize, &info, bisize);
memcpy(pBitmapFlashBuffer + fhsize + bisize, m_pFrameBuffer, size);
FILE *pFile = fopen(lpsFileName,"wb");
if (pFile)
{
fwrite(pBitmapFlashBuffer,1,fhsize + bisize + size,pFile);
fclose(pFile);
}
delete [] pBitmapFlashBuffer;
}
}