- // Fill in the DIB header
- lpDIBh->bmiHeader.biSize = headersize;
- lpDIBh->bmiHeader.biWidth = width;
- lpDIBh->bmiHeader.biHeight = -height;
- lpDIBh->bmiHeader.biSizeImage = bytePerLine * height;
- lpDIBh->bmiHeader.biPlanes = 1;
- lpDIBh->bmiHeader.biBitCount = 24;
- lpDIBh->bmiHeader.biCompression = BI_RGB;
- lpDIBh->bmiHeader.biClrUsed = 0;
- // These seem not really needed for our purpose here.
- lpDIBh->bmiHeader.biClrImportant = 0;
- lpDIBh->bmiHeader.biXPelsPerMeter = 0;
- lpDIBh->bmiHeader.biYPelsPerMeter = 0;
- // memory for DIB data
- unsigned char *lpBits;
- lpBits = (unsigned char *) malloc( lpDIBh->bmiHeader.biSizeImage );
- if( !lpBits )
- {
- wxFAIL_MSG( wxT("could not allocate data for DIB") );
- free( data );
- free( lpDIBh );
- return wxNullImage;
- }
-
- // copy data from the device-dependent bitmap to the DIB
- HDC hdc = ::GetDC(NULL);
- HBITMAP hbitmap;
- hbitmap = (HBITMAP) GetHBITMAP();
- ::GetDIBits( hdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS );
-
- // copy DIB data into the wxImage object
- int i, j;
- unsigned char *ptdata = data;
- unsigned char *ptbits = lpBits;
- for( i=0; i<height; i++ )
- {
- for( j=0; j<width; j++ )
- {
- *(ptdata++) = *(ptbits+2);
- *(ptdata++) = *(ptbits+1);
- *(ptdata++) = *(ptbits );
- ptbits += 3;
- }
- ptbits += padding;
- }