sara,
If you want to convert the image from 24-bits to 8-bits then you must define your own palette otherwise the bitmap will not be displayed properly. Since your image is appearing as black, then you must be doing something wrong along the way in processing the pixel data. Here is an example which loads a 24-bit image and then uses L_GetBitmapRow to get all of the pixel data and then it fills in a new bitmap of the same dimensions. The effect is that the image appears to be 33% of its original size because the pixel data is not being transformed it is simply being put in to the new bitmap byte by byte.
L_INT nRet;
L_UCHAR L_FAR *pBuf, *pBuf2, *pBuf3;
HGLOBAL hBuf, hBuf2, hBuf3;
BITMAPHANDLE newBitmap;
L_InitBitmap(&newBitmap, sizeof(BITMAPHANDLE), bitmap.Width, bitmap.Height, bitsPerPixel);
L_CopyBitmapPalette(&newBitmap, &bitmap);
L_AllocateBitmap(&newBitmap, TYPE_CONV);
L_AccessBitmap(&newBitmap);
L_AccessBitmap(&bitmap);
hBuf = GlobalAlloc(GMEM_MOVEABLE, bitmap.BytesPerLine);
pBuf = (L_UCHAR L_FAR *)GlobalLock(hBuf);
hBuf2 = GlobalAlloc(GMEM_MOVEABLE, bitmap.BytesPerLine * bitmap.Height);
pBuf2 = (L_UCHAR L_FAR *)GlobalLock(hBuf2);
hBuf3 = GlobalAlloc(GMEM_MOVEABLE, newBitmap.BytesPerLine);
pBuf3 = (L_UCHAR L_FAR *)GlobalLock(hBuf3);
for(L_INT nRow = 0; nRow<bitmap.Height; nRow++)
{
nRet = L_GetBitmapRow(&bitmap, pBuf, (bitmap.Height-1) - nRow, numbBytes);
if(nRet != numbBytes)
{
MessageBox(TEXT("Error getting data"));
return;
}
for(L_UINT uByte = 0; uByte < bitmap.BytesPerLine; uByte++)
{
pBuf2[(nRow * bitmap.BytesPerLine) + uByte] = pBuf[uByte];
}
}
for(L_INT nRow = 0; nRow<newBitmap.Height; nRow++)
{
for(L_UINT uByte = 0; uByte < newBitmap.BytesPerLine; uByte++)
{
pBuf3[uByte] = pBuf2[(nRow * bitmap.BytesPerLine) + uByte];
}
nRet = L_PutBitmapRow(&newBitmap, pBuf3, nRow, newBitmap.BytesPerLine);
if(nRet != newBitmap.BytesPerLine)
{
MessageBox(TEXT("Error putting data"));
return;
}
}
L_ReleaseBitmap(&newBitmap);
L_ReleaseBitmap(&bitmap);
L_FreeBitmap(&bitmap);
L_CopyBitmapHandle(&bitmap, &newBitmap, sizeof(BITMAPHANDLE));
GlobalUnlock(hBuf);
GlobalFree(hBuf);
GlobalUnlock(hBuf2);
GlobalFree(hBuf2);
GlobalUnlock(hBuf3);
GlobalFree(hBuf3);