unit WIN32_DIBs; {$MODE OBJFPC} {$M+} interface uses WIN32_Objects, Windows, type_fixes; { GDI provides the following functions to transfer bits from DIBs to DDBs, DDBs to DIBs and DIBs to DCs: * CreateDIBitmap() - this function creates a compatible device dependent bitmap, and initializes it with the passed in DIB. * GetDIBits() - this functions translates a DDBs data into a DIB that is passed in. * SetDIBits() - Like CreateDIBitmap, this function intializes a DDB using the DIB data that is passed in. * SetDIBitsToDevice() - This function copies a DIB directly (translating each pixel of course) onto a display device context. * StretchDIBits() - This function is similar to StretchBlt(), it stretches the source onto a DCs surface - the source data is a DIB. CPaintDC dc(this); // device context for painting DWORD dwBits[] = ... 0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000, 0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000, 0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000, 0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000...; BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 4; bmi.bmiHeader.biHeight = 4; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc,4,4); ::SetDIBits(dc.m_hDC,bitmap,0,4,&dwBits,&bmi,DIB_RGB_COLORS); CDC dcMemory; dcMemory.CreateCompatibleDC(&dc); CBitmap * pOldBitmap = dcMemory.SelectObject(&bitmap); dc.BitBlt(0, 0, 4, 4, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); } { HDIB DrawTextInDIB(HDIB hDIB, LPCSTR szText) HBITMAP hBitmap, hbmo HDC hMemDC; HDIB hNewDIB; hBitmap = BitmapFromDIB(hDIB, NULL); hMemDC = CreateCompatibleDC(NULL); hbmo = SelectObject(hMemDC, hBitmap); TextOut( hMemDC, 10, 10, szText, lstrlen(szText) ); SelectObject(hMemDC, hbmo); DeleteDC(hMemDC); hNewDIB = DIBFromBitmap(hBitmap, BI_RGB, 0, NULL); DeleteObject(hBitmap); return hNewDIB; } end.