Archived

This topic is now archived and is closed to further replies.

David_Kay

8-bit bitmap

Recommended Posts

Hello, I keep trying to load a 8-bit bitmap and when I extract the values/color of a pixel at x, y I always get the wrong color from the palette. Does anyone know of a function, and/or site that will tell me how to do it correctly? My function is in my class here: (*note* this is a 8-bit bitmap for a height map - grayscale) #ifndef CXHEIGHTMAP_H #define CXHEIGHTMAP_H #include void SetError(char* String){ OutputDebugString( "ERROR: " ); OutputDebugString( String ); OutputDebugString( "\n" ); } class CXHeightMap { public: CXHeightMap(); ~CXHeightMap(); // Function public: int LoadMap( char* szPath ); // Variables public: BITMAPFILEHEADER bitmapfileheader; BITMAPINFOHEADER bitmapinfoheader; PALETTEENTRY palette[256]; BYTE *buffer; int nWidth, nHeight; }; //--------------------------------------------------------------- // //--------------------------------------------------------------- inline CXHeightMap::CXHeightMap() { for( int i = 0; i < 256; i++){ palette[i].peBlue = i; palette[i].peGreen = i; palette[i].peRed = i; palette[i].peFlags = PC_NOCOLLAPSE; } buffer = NULL; } //--------------------------------------------------------------- // //--------------------------------------------------------------- inline CXHeightMap::~CXHeightMap() { if(buffer) delete[] buffer; } //--------------------------------------------------------------- // //--------------------------------------------------------------- inline int CXHeightMap::LoadMap( char* szPath ) { if(lstrlen(szPath) <= 2){ SetError( "szPath <= 2" ); return 0; } int file_handle; OFSTRUCT file_data; if((file_handle = OpenFile( szPath, &file_data, OF_READ)) == -1){ SetError( "file_handle == -1"); return 0; } // load the bitmap file header _lread(file_handle, &bitmapfileheader, sizeof(BITMAPFILEHEADER)); // see if the image from the path is a bitmap file if( bitmapfileheader.bfType != 0x4D42 ){ SetError( szPath ); SetError( "Is not a bitmap!" ); _lclose(file_handle); return 0; } _lread(file_handle, &bitmapinfoheader, sizeof(BITMAPINFOHEADER)); _lseek(file_handle, -(int)(bitmapinfoheader.biSizeImage) , SEEK_END); if(bitmapinfoheader.biBitCount == 8){ if( buffer ) delete[] buffer; buffer = new BYTE[bitmapinfoheader.biSizeImage]; UINT nRead = 0; nRead = _lread(file_handle, buffer, bitmapinfoheader.biSizeImage); cout << "nRead = " << nRead << endl; } else{ SetError( "biBitCount != 8 bits" ); return 0; } nHeight = bitmapinfoheader.biHeight; nWidth = bitmapinfoheader.biWidth; _lclose(file_handle); return 1; } #endif Edited by - David_Kay on October 23, 2001 8:36:38 PM Edited by - David_Kay on October 23, 2001 8:37:09 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Might want to try flipcode.com ..... not sure though.

Share this post


Link to post
Share on other sites