vorrei visualizzare una immagine in una finestra. credo che il primo passo sia quello di trasformare il buffer che contiene l'immagine in un DDB,device dependent bitmap, e poi sivualizzare l'immagine utilizzando device contexts e BitBlt().
l'immagine non è un file, è generata dal mio porgramma in questo formato:
so che l'immagine è un 640x400 pixel, e il buffer che la contiene è
char *bit24format;
ogni pixel è rappresentato da 3 bytes del buffer, in formato RGB, quindi la struttura del buffer è
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
il codice che posto è come ho cercato di fare la cosa, ma non funziona. al posto della mia immagine compare una immagine 640x400 completamente nera...
cosa sbaglio?? grazie mille!!!
codice: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);

Rispondi quotando