Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with save picture to BMP in VC++

Status
Not open for further replies.

Bartec

Programmer
Jan 21, 2005
54
PL
Hi!

My problem looks quite strange baecause when I save to bmp file my picture is saved upside down..:)I need to save it in rigth order but I don't know how. Below my code which I use to save the picture:
//////////////////////////////////////////////////////////////
HANDLE hf = CreateFile("C:\\!!BMP\\SKRP.bmp", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL );
if( hf == INVALID_HANDLE_VALUE )
{
return ;
}
BITMAPFILEHEADER bfh;
memset( &bfh, 0, sizeof( bfh ) );
bfh.bfType = 'MB';
bfh.bfSize = sizeof( bfh ) + dwSize + sizeof( BITMAPINFOHEADER );
bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER );

DWORD Written = 0;
WriteFile( hf, &bfh, sizeof( bfh ), &Written, NULL );


///
// Write the bitmap format
//
BITMAPINFOHEADER bih;
memset( &bih, 0, sizeof( bih ) );
bih.biSize = sizeof( bih );
bih.biWidth = 320;
bih.biHeight = 240 ;
bih.biPlanes = 0;
bih.biBitCount = 24;
bih.biCompression = BI_RGB;
bih.biClrImportant = 0;
bih.biClrUsed = 0;

Written = 0;
WriteFile( hf, &bih, sizeof( bih ), &Written, NULL );
// Write the bitmap bits
//
Written = 0;
WriteFile( hf, pImage, dwSize, &Written, NULL );

CloseHandle( hf );
//////////////////////////////////////////////////////////

Thats all. If anybody knows what I'm doing wrong please reply on my question.

Best regards

Bartec

 
I seem to recall that BMP files are stored upside down, that is the data at the start of the BMP is bottom of the picture and the data at the end is the top of the picture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top