Skip to main content
gamedev.net
🔒 Locked

Bitmap loader problem

Started by Thomo May 27, 2006 at 6:34 AM 0 replies 350+ views
Original Post
Thomo
Thomo
I'm trying to load a bitmap with a small win32 console application. I do the following:


	// load in the bitmap image
	HBITMAP bit = (HBITMAP) LoadImage(NULL, "head 1_eyeL_hi.bmp", IMAGE_BITMAP, 0, 0,
								LR_DEFAULTSIZE | LR_LOADFROMFILE);

	if (!bit) 

		// failed to load, return failure to caller
		printf("bitmap not loaded");

	// get bitmap dimensions
	BITMAP bitmap;
    GetObject( bit, sizeof(BITMAP), &bitmap );

	printf("width = %d\n\n", bitmap.bmType);

	//BYTE *byBitData = (BYTE *) calloc(bitmap.bmBitsPixel * bitmap.bmHeight * bitmap.bmWidth, sizeof(BYTE));
	BYTE *byBitData = (BYTE *) calloc(64*64, sizeof(BYTE));

	byBitData = (BYTE *) bitmap.bmBits;

	// get the pixel bits
	printf("bits = %d\n\n", byBitData[0]);
The program crashes when trying to print the first bit data. The debugger says that byBitData and bitmap.bmBits are bad pointer. Sure enough, when I print them to the screen they are null (0.000). Dont know what I'm doing wrong here, hoe someone can help.
yadango
yadango
from MSDN on GetObject:
If hgdiobj is a handle to a bitmap created by any other means (ie any function other than CreateDIBSection), GetObject returns only the width, height, and color format information of the bitmap. You can obtain the bitmap's bit values by calling the GetDIBits or GetBitmapBits function.

Topic Locked

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

Sign in to reply to this topic.