Skip to main content
gamedev.net
🔒 Locked

Reading pixels from bmp

Started by Florian22222 Dec 23, 2011 at 7:23 AM 0 replies 500+ views
Original Post
Florian22222
Florian22222
I wrote a little program to read pixels from a bmp.
But it isn´t working. The "apply.a.bmp" is a 40x40 8bit bitmap.



int main()
{
FILE *f;
BITMAPINFOHEADER header;
f=fopen("apply.a.bmp","r");

fread(&header,sizeof(header),1,f);

int size = header.biBitCount; //in byte

int i = 0;
void *pixel = malloc(size);
while(feof(f) == 0)
{
i++;
fread(&pixel,sizeof(pixel),1,f);
cout << (int)pixel << endl;
};

cout << i << " byte red" << endl;

fclose(f);

system("pause");
return 0;
}



on the end it prints "373 byte red".

Where is my fault?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.