C++ 在写入BMP文件后,图像被翻转过来
我正在使用以下代码:C++ 在写入BMP文件后,图像被翻转过来,c++,xcode,image,opengl,bmp,C++,Xcode,Image,Opengl,Bmp,我正在使用以下代码: f = fopen( _stringhelper.STR("%s.bmp", filename), "wb" ); if( !f ) { _core.Error( ERC_ASSET, "ncImageLoader::CreateImage - Couldn't create %s image.\n", filename ); return false; } int w = width; int h = height; int i; int filesi
f = fopen( _stringhelper.STR("%s.bmp", filename), "wb" );
if( !f ) {
_core.Error( ERC_ASSET, "ncImageLoader::CreateImage - Couldn't create %s image.\n", filename );
return false;
}
int w = width;
int h = height;
int i;
int filesize = 54 + 3 * w * h;
byte bmpfileheader[14] = {
'B', 'M',
0, 0, 0, 0,
0, 0,
0, 0,
54, 0, 0, 0 };
byte bmpinfoheader[40] = { 40, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 0,
24, 0};
byte bmppad[3] = { 0, 0, 0 };
bmpfileheader[2] = (byte)( filesize );
bmpfileheader[3] = (byte)( filesize >> 8 );
bmpfileheader[4] = (byte)( filesize >> 16 );
bmpfileheader[5] = (byte)( filesize >> 24 );
bmpinfoheader[4] = (byte)( w );
bmpinfoheader[5] = (byte)( w >> 8);
bmpinfoheader[6] = (byte)( w >> 16 );
bmpinfoheader[7] = (byte)( w >> 24);
bmpinfoheader[8] = (byte)( h );
bmpinfoheader[9] = (byte)( h >> 8 );
bmpinfoheader[10] = (byte)( h >> 16 );
bmpinfoheader[11] = (byte)( h >> 24 );
fwrite( bmpfileheader, 1, 14, f );
fwrite( bmpinfoheader, 1, 40, f );
for( i = 0; i < h; i++ ) {
fwrite( data + ( w * (h - i - 1) * 3 ), 3, w, f );
fwrite( bmppad, 1, ( 4 - ( w * 3 ) % 4 ) % 4, f );
}
fclose(f);
f=fopen(_stringhelper.STR(“%s.bmp”,文件名),“wb”);
如果(!f){
_错误(ERC_资产,“ncImageLoader::CreateImage-无法创建%s映像。\n”,文件名);
返回false;
}
int w=宽度;
int h=高度;
int i;
int filesize=54+3*w*h;
字节bmpfileheader[14]={
‘B’、‘M’,
0, 0, 0, 0,
0, 0,
0, 0,
54, 0, 0, 0 };
字节bmpinfoheader[40]={40,0,0,0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 0,
24, 0};
字节bmppad[3]={0,0,0};
bmpfileheader[2]=(字节)(文件大小);
bmpfileheader[3]=(字节)(文件大小>>8);
bmpfileheader[4]=(字节)(文件大小>>16);
bmpfileheader[5]=(字节)(文件大小>>24);
bmpinfoheader[4]=(字节)(w);
bmpinfoheader[5]=(字节)(w>>8);
bmpinfoheader[6]=(字节)(w>>16);
bmpinfoheader[7]=(字节)(w>>24);
bmpinfoheader[8]=(字节)(h);
bmpinfoheader[9]=(字节)(h>>8);
bmpinfoheader[10]=(字节)(h>>16);
bmpinfoheader[11]=(字节)(h>>24);
fwrite(bmpfileheader,1,14,f);
fwrite(bmpinfoheader,1,40,f);
对于(i=0;i
我正在使用glReadPixels()
捕获显示数据。如果我转到保存此文件的文件夹并打开它-很好,调色板很好,但它是颠倒的。我试着“向后”写for循环,但还是一无所获。。我不明白
可能有什么问题?位图是“倒置”存储的,请参阅此处的更多信息:
可以将高度设置为负值,以使其正确显示。(-高度)
从:
如果biHeight为负数,则位图为自上而下的DIB,具有
原点位于左上角
你能为循环向后显示你的
吗?(当前的一个实际上是“向后的”,但这是因为BMP需要它。)