I'm tring to display a Bitmap that I read from a file with my own format. Data is stored with 16 bitsxcolor . When I create a bitmap with CreateBitmap it displays ok if screen uses 16bitsxcolor but not in other cases.
So, I have tried to create a Device Independent Bitmap with CreateDIBSection. Image is created correctly but colors are not displayed ok. Anyone can help me?
This is the code I use to create the bitmap with CreateBitmap
This is the code I use to create with CreateDIBSection
HDC dc= CreateCompatibleDC(NULL);
BITMAPINFO i;
ZeroMemory( &i.bmiHeader, sizeof(BITMAPINFOHEADER) );
i.bmiHeader.biWidth=bm.l; // Set size you need
i.bmiHeader.biHeight=-bm.a; // Set size you need
i.bmiHeader.biPlanes=1;
i.bmiHeader.biBitCount=16; // Can be 8, 16, 32 bpp or other number
i.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
VOID *pvBits;
HBITMAP hbmp= CreateDIBSection( dc, &i, DIB_RGB_COLORS, &pvBits, NULL, 0 );
SetDIBits(dc,hbmp,0,bm.a,bm.bits,&i,DIB_RGB_COLORS);
free(bm.bits);
im.bitmap->Attach(hbmp);
DeleteObject(dc);
Lixiang
May 26th, 2004, 12:42 AM
try to add the following line:
(i.bmiHeader).biCompression = BI_RGB;
JuanjoBP
May 26th, 2004, 03:42 AM
I have added this line and it still does not work
i.bmiHeader.biCompression=BI_RGB;
Lixiang
May 26th, 2004, 08:49 AM
i.bmiHeader.biHeight=-bm.a;
why it is negative?
JuanjoBP
May 26th, 2004, 11:23 AM
I use a negative value because the consecuence is that image is vertically flipped if I don't use. In msdn page it explains to use a negative value in order to display image from top-left to bottom-right.
Lixiang
May 26th, 2004, 10:22 PM
I wrote a test program, tested it in Win2K and Win98, everything seems OK.
I think the problem is with red color. I fill my image with all green intensity values, and same with blue, and the result is the expected, but if I do the same with red, the result is not what it should be.
I suggest you to modify your SetMyBits function with something like this.
void CBmpDlg::SetMyBits(WORD MyBits[], int nBitsLen, WORD wColor)
{
short red;
red=0x001f;
for (int ii = 0; ii < nBitsLen; ii += 1)
{
MyBits[ii] = red<<11;
red--;
if(red==0)
red=0x001f;
}
}
JuanjoBP
May 27th, 2004, 05:54 AM
I think I have found the problem!!
SetDIBits interprets the 16 bits of a color to be in format 1:5:5:5 while if I create the bitmap by CreateBitmap and SetBitmapBits, it is interpreted to be in 5:6:5 format.
Thank you for your help, Lixiang.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.