I tested my code on a 16x16 BMP image and the output is weird indeed. I mem filled the data with RGB(0,0,255)(Blue) and then wrote it to file.
Except, the output was a mini bar graph, that had all 3 of the colors in it. I dunno why. What is wrong with my above code(Except that I now aligned the headers.
Toolmaker
-Earth is 98% full. Please delete anybody you can.
Saving a 24bit bitmap?
Are you sure your surface is 24 bits? It''s just a byte pointer in your function, so there''s no hints to its actual structure, but what you''re describing could result from reading a 32 bit surface as a 24 bit surface.
Here is the part of my DIB bitmap class that actually saves the DIB to a file. There are probably cleaner more flexible ways to do this but I know it saves a 24 bit bitmap that I can view in ms paint, the picture and fax viewer, paint shop pro and photoshop. I know it uses fopen/fwrite instead of streams but the concept is the same (I think).
I hope that makes sense. If not, just ask and I think I can explain better.
Evillive2
E-Mail
// m_bmfh - bmp file header// m_bmih - bmp info header// m_width - bmp width in pixels// m_height - bmp height in pixelsvoid CDIBBMP::SaveToFile( char *strFile ){ FILE *fp = NULL; int y, pad_bytes; BYTE pad[4] = {0,0,0,0}; if ( (fp = fopen( strFile, "wb" )) == NULL ) { // error msg return; } if ( (pad_bytes = sizeof(BYTE)*m_width*3 % 4) ) pad_bytes = 4 - pad_bytes; m_bmfh.bfSize = sizeof( m_bmfh ) + sizeof( m_bmih ) + (sizeof(BYTE)*m_width*m_height*3) + (pad_bytes*m_height); m_bmfh.bfOffBits = sizeof( m_bmfh ) + sizeof( m_bmih ); m_bmfh.bfType = ''MB''; m_bmfh.bfReserved1 = 0; m_bmfh.bfReserved2 = 0; fwrite( &m_bmfh, sizeof(m_bmfh), 1, fp ); fwrite( &m_bmih, sizeof(m_bmih), 1, fp ); // bitmaps are saved upside down for some reason so we flip it // and save one row at a time for ( y = m_height -1; y >=0; y-- ) { fwrite( &m_pbits[y*m_width*3], sizeof(BYTE)*3, m_width, fp ); fwrite( pad, sizeof(BYTE), pad_bytes, fp ); } fclose(fp);}
I hope that makes sense. If not, just ask and I think I can explain better.
Evillive2
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement