[Solved] Why the C++ code couldn’t display bitmap?(code from textbook) [closed]


Running your code, put aside the code logic first, just to show the BMP image, you did not add the correct image path.

You can try to add the absolute path of the picture.

Like this:

DrawBitmap("C:\\Users\\strives\\source\\C.bmp",x,y); //This is my picture path. Please enter your picture path correctly.

Updated:

I retested the code with MinGW, GCC 4.9.2 compiler. It can display the image correctly. Look at my attached GIF picture.

1

From the results of your feedback later, Loadimage return NULL, you use GetLasterror to test the return value of 0. In theory, if the image failed to load, it will return 2. Maybe you can use int error = GetLasterror() to retest the return value. At the same time, you need to make sure that the BMP image you added is correct, opened, and in BMP format. picture

5

solved Why the C++ code couldn’t display bitmap?(code from textbook) [closed]