Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Creating bitmap in color

Tomas750
Beginner
516 Views
I have tried to fill bitmap created by function CreateDIBSection with some graph (lines and shapes of various colors). Although 24 bits for colors are declared there, only four distinct colors were finally found when using the function GetDIBits for retrieving the bitmap. The rest is changed into white. What is wrong?
0 Kudos
3 Replies
Paul_Curtis
Valued Contributor I
516 Views
You would need to post your code before anyone can try to help you with this.
0 Kudos
Tomas750
Beginner
516 Views

integer*4 hdcBits, cClrBits

integer*4 nBitmapWidth, nBitmapHeight

integer*4 hBitmap, hOldBitmap ! bitmap handle

integer(1), ALLOCATABLE:: lpBits(:)

integer(1), ALLOCATABLE:: lpBitsCompr(:)

pointer (p, pbmi)

type (T_BITMAPINFO) pbmi

........

cClrBits = 24

nMem = SizeOf(pbmi%bmiHeader)

p = LocalAlloc(LPTR, nMem)

! Prepare BITMAPINFO for the bitmap

pbmi%bmiHeader%biSize = SizeOf(pbmi%bmiHeader)

pbmi%bmiHeader%biWidth = nBitmapWidth

pbmi%bmiHeader%biHeight = nBitmapHeight

pbmi%bmiHeader%biPlanes = 1

pbmi%bmiHeader%biBitCount = cClrBits

pbmi%bmiHeader%biCompression = BI_RGB

pbmi%bmiHeader%biSizeImage = IAND(pbmi%bmiHeader%biWidth * cClrBits + 31, INOT(31))/8 * pbmi%bmiHeader%biHeight

pbmi%bmiHeader%biXPelsPerMeter = 0

pbmi%bmiHeader%biYPelsPerMeter = 0

pbmi%bmiHeader%biClrUsed = 0

if (cClrBits < 16) pbmi%bmiHeader%biClrUsed = 2**cClrBits

pbmi%bmiHeader%biClrImportant = 0

ALLOCATE(lpBits(pbmi%bmiHeader%biSizeImage), STAT=AllocErr)

if (AllocErr == 0) then

hBitmap = CreateDIBSection(hDC, pbmi, DIB_RGB_COLORS, LOC(lpBits), 0, 0)

hdcBits = CreateCompatibleDC(hDC)

hOldBitmap = SelectObject(hdcBits, hBitmap)

! Prepare the bitmap by painting the spectrum

call CfPrBMP(hdcBits, nBitmapWidth, nBitmapHeight)

! Replace a new object with the original, default object

i = SelectObject(hdcBits, hOldBitmap)

! Retrieve the color table (RGBQUAD array) and the bits (array of palette indices) from the DIB.

nScan = GetDIBits(hdcBits, hBitmap, 0, pbmi%bmiHeader%biHeight, loc(lpBits), loc(pbmi), DIB_RGB_COLORS)

........

end if

0 Kudos
Paul_Curtis
Valued Contributor I
516 Views

Take a look at the arguments for calling GetDIBits; according to MS,

"If lpvBits is NULL and the bit count member of BITMAPINFO is initialized to zero, GetDIBits fills in a BITMAPINFOHEADER structure or BITMAPCOREHEADER without the color table. This technique can be used to query bitmap attributes."

So if you call with null values [ie, GetDIBits (hdc, hbitmap, 0, 0, 0, LOC(bitmapInfo), DIB_RGB_COLORS)] the colormap properties are returned in the info header structure.
0 Kudos
Reply