- // similarly, set data according to the possible mask bitmap
- if( GetMask() && GetMask()->GetMaskBitmap() )
- {
- hbitmap = (HBITMAP) GetMask()->GetMaskBitmap();
- // memory DC created, color set, data copied, and memory DC deleted
- HDC memdc = ::CreateCompatibleDC( hdc );
- ::SetTextColor( memdc, RGB( 0, 0, 0 ) );
- ::SetBkColor( memdc, RGB( 255, 255, 255 ) );
- ::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS );
- ::DeleteDC( memdc );
- // background color set to mask colour
- unsigned char r=MASK_RED, g=MASK_GREEN, b=MASK_BLUE;
- ptdata = data;
- ptbits = lpBits;
- for( i=0; i<height; i++ )
- {
- for( j=0; j<width; j++ )
- {
- // is this pixel transparent?
- if ( *ptbits != 0 )
- {
- if ( (ptdata[0] == MASK_RED) &&
- (ptdata[1] == MASK_GREEN) &&
- (ptdata[2] == MASK_BLUE) )
- {
- // we have to fudge the colour a bit to prevent this
- // pixel from appearing transparent
- ptdata[2] = MASK_BLUE_REPLACEMENT;
- }
- ptdata += 3;
- }
- else // masked pixel
- {
- *(ptdata++) = MASK_RED;
- *(ptdata++) = MASK_GREEN;
- *(ptdata++) = MASK_BLUE;
- }
- ptbits += 3;
- }
- ptbits += padding;
- }
-
- image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
- image.SetMask( TRUE );
- }
- else
- {
- image.SetMask( FALSE );
- }
- // free allocated resources
- ::ReleaseDC(NULL, hdc);
- free(lpDIBh);
- free(lpBits);
-