Creating a DDB...

ok, i would like to print a picture in a window. I think that the first step should be to transform the data i have into a DDB, device dependent bitmap... and then i can copy it in my windows using device contexts and BitBlt().

this image is not in a file, it is generated dinamically. i explain you whitch data i have:
I have the size of the image, that is 640x400 and i know that the pixels are in the buffer
char *bit24format;
each pixel is rappresented by three bytes, in RGB format.
so the structure of my array is
pixel 1 red, pixel 1 green, pixel 1 blue, pixel 2 red, pixel 2 green, pixel 2 blue, pixel 3 red, .... etc....
so the size of the buffer will be 640*400*3

reading the msdn, I decided to solve the problem in this way, but it does not work, and the window display a black rectangle instead of my image.

what is wrong?? thank you very much!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	BITMAPINFO info;

	info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	info.bmiHeader.biWidth = 640;
	info.bmiHeader.biHeight = 400;
	info.bmiHeader.biPlanes = 1;
	info.bmiHeader.biBitCount = 24;
	info.bmiHeader.biCompression = BI_RGB;
	info.bmiHeader.biSizeImage = bit24format_size;
	info.bmiHeader.biXPelsPerMeter = 0;
	info.bmiHeader.biYPelsPerMeter = 0;
	info.bmiHeader.biClrUsed = 0;
	info.bmiHeader.biClrImportant = 0;

	PAINTSTRUCT ps;
	HDC hdc = BeginPaint(finestra_principale, &ps);
	if(hdc == NULL) MessageBox( NULL, "BeginPaint", "ERRORE", MB_OK);
	HDC cdc = CreateCompatibleDC(hdc);

	//HBITMAP immagine = CreateDIBitmap(cdc, &info.bmiHeader, CBM_INIT, (void *) bit24format, &info, 0);
	//if(immagine == NULL) MessageBox( NULL, "CreateDIBitmap", "ERRORE", MB_OK);
	HBITMAP immagine = CreateCompatibleBitmap(cdc, 640, 400);
	int control = SetDIBits(cdc, immagine, 1, 399, (void *) bit24format, &info, DIB_PAL_COLORS);
	bit24format[10]='\0';
	sprintf(video_text, "SetDIBits: %d", control);
	MessageBox( NULL, video_text, "dati", MB_OK);

	SelectObject(cdc, immagine);

	BitBlt(hdc, 0, 0, 640, 400, cdc, 0, 0, SRCCOPY);
	DeleteDC(cdc);
	DeleteObject(immagine);
	EndPaint(finestra_principale, &ps);
I wonder if this is pallette related - because DIB_PAL_COLORS meas to use colours as defined by
the pallette currently selected into the device context - and you only appear to have the default pallette.

I'm not sure what this bit24format[10]='\0'; does
and I think this
SetDIBits(cdc, immagine, 1, 399, (void *) bit24format, &info, DIB_PAL_COLORS);
should be
SetDIBits(cdc, immagine, 0, 400, (void *) bit24format, &info, DIB_PAL_COLORS);

Last edited on
Topic archived. No new replies allowed.