• Advertisement
Sign in to follow this  

Strange end of file error

This topic is 4974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently writing a function that's supposed to draw a BMP file (24bit per color) on the screen.

-----------FUNCTION----------------

        FILE *f;
	BITMAPFILEHEADER bitmapfileheader;
	BITMAPINFOHEADER bitmapinfoheader;
	int i, x, y;
	char c[3];

//	t = (Texture*) malloc(sizeof(Texture));

	f=fopen(File...., "r");

	fread(&bitmapfileheader, sizeof(BITMAPFILEHEADER), 1, f);
	fread(&bitmapinfoheader, sizeof(BITMAPINFOHEADER), 1, f);

	HDC	hdc;
	hdc = GetDC(mHwnd);

	for (y=0;y<bitmapinfoheader.biHeight;y++)
	{
		for (x=0;x<bitmapinfoheader.biWidth;x++)
		{
			fread(c, sizeof(char), 3, f);
			SetPixel(hdc, int(x), int(y), RGB(c[0],c[1],c[2]));
		}
	
	}
	Sleep(3000);
	PostQuitMessage(0);
	fclose(f);

According to bitmapfileheader.bfSize the file is 1440056 byte large Yet i can only read aprox. 16686 bytes. Anyone know what i'm doing wrong??

Share this post


Link to post
Share on other sites
Advertisement
First thing, if it's a bitmap file, you should open it with f=fopen(filename, "rb");

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement