I read a LOT of tutorials on bitmaps. I learned that RGBQuad is for 32 bit bitmaps and RGBTripple is for 24 bit bitmaps..
I'm planning on getting pixel information from a bitmap that can be of 3 types. 24bit, 32bit, 32bit with alpha (Transparent).
Thing is, I don't know how to determine what types of bitmaps I'm loading (24, 32, 32a).
I have to be able to draw these to a Window/DC.
This is what I have so far.. Can anyone point me in the right direction? Can I use LoadImage?
#include <windows.h>
#include <iostream>
using namespace std;
/** 24-Bit Bitmaps **/
class TBitmap
{
private:
HANDLE hFile;
DWORD Written;
BITMAPFILEHEADER bFileHeader;
BITMAPINFOHEADER bInfoHeader;
RGBTRIPLE *Image;
public:
void LoadBitmapFromFile(const char* FilePath)
{
/** Open File **/
hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
/** Read Header **/
ReadFile(hFile,&bFileHeader,sizeof(bFileHeader),&Written,NULL);
ReadFile(hFile,&bInfoHeader,sizeof(bInfoHeader),&Written,NULL);
/** Read Image **/
int imagesize = bInfoHeader.biWidth * bInfoHeader.biHeight; //Math to Allocate memory for the inamge.
Image = new RGBTRIPLE[imagesize]; //Create a new image. Array.
ReadFile(hFile, Image, imagesize * sizeof(RGBTRIPLE), &Written, 0); //Reads images.
CloseHandle(hFile); //Close File Handle.
}
/** GetPixel Location **/
RGBTRIPLE GetPixel(int X, int Y)
{
return Image[(bInfoHeader.biHeight - 1 - Y) * bInfoHeader.biWidth + X]; //BMP is upside-down due to the way screen co-ordinates work.
}
/** Set Pixel Colour **/
RGBTRIPLE SetPixel(int X, int Y, RGBTRIPLE Colour)
{
Image[(bInfoHeader.biHeight - 1 - Y) * bInfoHeader.biWidth + X] = Colour;
}
};
int main()
{
TBitmap BMP;
BMP.LoadBitmapFromFile("Untitled.bmp");
cin.get();
}