I followed a tutorial to load a bitmap from file and convert it to a array of bytes to access it directly. Now to display the bitmap on screen do I have to convert it to a HBITMAP or can I display it from the array of bytes?
Also the program I am building is a calendar program and I need to know if I can manipulate the bitmaps pixels in the byte array (e.g change color and resize image)
here is the code to load the bitmap
HTML Code:
BYTE* Sprite2::LoadBMP(int* width, int* height, long* size, LPCTSTR bmpfile )
{
BITMAPFILEHEADER bmpheader;
BITMAPINFOHEADER bmpinfo;
DWORD bytesread;
HANDLE file = CreateFile(bmpfile,GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
if(0 == file)
return 0;
if(ReadFile ( file, &bmpheader, sizeof( BITMAPFILEHEADER),
&bytesread, 0 ) == false )
{
CloseHandle (file );
return 0;
}
if( ReadFile ( file, &bmpinfo, sizeof ( BITMAPINFOHEADER ),
&bytesread, 0 ) == false )
{
CloseHandle ( file );
return 0;
}
if( bmpheader.bfType != 'MB' )
{
CloseHandle( file );
return 0;
}
if( bmpinfo.biCompression != BI_RGB )
{
CloseHandle( file );
return 0;
}
if( bmpinfo.biBitCount != 24 )
{
CloseHandle( file );
return 0;
}
*width = bmpinfo.biWidth;
*height = abs (bmpinfo.biHeight);
*size = bmpheader.bfSize - bmpheader.bfOffBits;
BYTE* Buffer = new BYTE[ *size ];
SetFilePointer ( file, bmpheader.bfOffBits, 0, FILE_BEGIN );
if( ReadFile (file, Buffer, *size, &bytesread, 0 ) == false)
{
delete [] Buffer;
CloseHandle( file );
return 0;
}
CloseHandle( file );
return Buffer;
}