G
Guest
My code compiles without any errors and the only warnings are irrelevant to
the function used to load and display the image with. The file loads
properly, but DrawDibDraw isn't displaying anything at all. What's wrong
with it? The BMP image itself should be very easily detected - it's black
with colored stars behind very colorful 3D text that has realistic lighting.
Why doesn't it display the image, not a single pixel of it? The
"window_size_base" values are the interior (white) space of the window, which
is 640 pixels wide and 480 high. The image itself is 512x384, both multiples
of 4 and thus no extra zeros are needed (spacers). There should be 64 pixels
on the left and right edges of white space and 48 from the top and bottom.
This is the area where I've started the drawing part:
the function used to load and display the image with. The file loads
properly, but DrawDibDraw isn't displaying anything at all. What's wrong
with it? The BMP image itself should be very easily detected - it's black
with colored stars behind very colorful 3D text that has realistic lighting.
Why doesn't it display the image, not a single pixel of it? The
"window_size_base" values are the interior (white) space of the window, which
is 640 pixels wide and 480 high. The image itself is 512x384, both multiples
of 4 and thus no extra zeros are needed (spacers). There should be 64 pixels
on the left and right edges of white space and 48 from the top and bottom.
This is the area where I've started the drawing part:
Code:
FILE *file_handle; // handle for reading/writing files
char bmp_image[589824]; // data for the bitmap image // 589878 bytes is the
file size
char error_msg[256]; // string for indicating errors
HDRAWDIB img_handle; // pointer for a DrawDib handle
HWND hwnd; // window handle
HDC HDC_handle; // pointer for HDC handle
WNDCLASSEX windowClass; // for a window class
MSG msg; // a message for windows
LPBITMAPINFOHEADER bmp_head_pointer;
LPVOID bmp_image_pointer;
BITMAPFILEHEADER bmp_filehead;
BITMAPINFOHEADER bmp_head;
void draw_test_image()
{
img_handle = DrawDibOpen();
file_handle = fopen("C:\\My Documents\\My programs\\ulillilliacity.bmp",
"rb"); // read the source BMP file to display, binary mode
fread(&bmp_filehead.bfType, 2, 1, file_handle); // bytes 00 and 01
fread(&bmp_filehead.bfSize, 4, 1, file_handle); // 02 through 05
fread(&bmp_filehead.bfReserved1, 2, 1, file_handle); // 06 and 07
fread(&bmp_filehead.bfReserved2, 2, 1, file_handle); // 08 and 09
fread(&bmp_filehead.bfOffBits, 4, 1, file_handle); // 0A through 0D
// fill the bitmap info header struct reading from the file
fread(&bmp_head.biSize, 4, 1, file_handle); // bytes 0E through 11
fread(&bmp_head.biWidth, 4, 1, file_handle); // 12 through 15
fread(&bmp_head.biHeight, 4, 1, file_handle); // 16 through 19
fread(&bmp_head.biPlanes, 2, 1, file_handle); // 1A and 1B
fread(&bmp_head.biBitCount, 2, 1, file_handle); // 1C and 1D
fread(&bmp_head.biCompression, 4, 1, file_handle); // 1E through 21
fread(&bmp_head.biSizeImage, 4, 1, file_handle); // 22 through 25
fread(&bmp_head.biXPelsPerMeter, 4, 1, file_handle); // 26 through 29
fread(&bmp_head.biYPelsPerMeter, 4, 1, file_handle); // 2A through 2D
fread(&bmp_head.biClrUsed, 4, 1, file_handle); // 2E through 31
fread(&bmp_head.biClrImportant, 4, 1, file_handle); // 32 through 35
fread(&bmp_image, 1, bmp_head.biSizeImage, file_handle); // read the
remainder of the bits, the image data part // bytes 36 and onward
fclose(file_handle);
DrawDibDraw(img_handle, HDC_handle,
window_size_base.x/2-bmp_head.biWidth/2,
window_size_base.y/2-bmp_head.biHeight/2, bmp_head.biWidth,
bmp_head.biHeight, bmp_head_pointer, bmp_image_pointer, 0, 0,
bmp_head.biWidth, bmp_head.biHeight, NULL); // center the full image in the
window
DrawDibClose(img_handle); // free the resources since only one "render" is
made
ReleaseDC(hwnd, HDC_handle); // free the DC handle
}