CImage::TransparentBlt

Copies a bitmap from the source device context to this current device context.

BOOL TransparentBlt( 
   HDC hDestDC, 
   int xDest, 
   int yDest, 
   int nDestWidth, 
   int nDestHeight, 
   UINT crTransparent = CLR_INVALID  
) const throw( ); 
BOOL TransparentBlt( 
   HDC hDestDC, 
   const RECT& rectDest, 
   UINT crTransparent = CLR_INVALID  
) const throw( ); 
BOOL TransparentBlt( 
   HDC hDestDC, 
   int xDest, 
   int yDest, 
   int nDestWidth, 
   int nDestHeight, 
   int xSrc, 
   int ySrc, 
   int nSrcWidth, 
   int nSrcHeight, 
   UINT crTransparent = CLR_INVALID  
) const throw( ); 
BOOL TransparentBlt( 
   HDC hDestDC, 
   const RECT& rectDest, 
   const RECT& rectSrc, 
   UINT crTransparent = CLR_INVALID  
) const throw( );

Parameters

  • hDestDC
    A handle to the destination device context.

  • xDest
    The x-coordinate, in logical units, of the upper left corner of the destination rectangle.

  • yDest
    The y-coordinate, in logical units, of the upper left corner of the destination rectangle.

  • nDestWidth
    The width, in logical units, of the destination rectangle.

  • nDestHeight
    The height, in logical units, of the destination rectangle.

  • crTransparent
    The color in the source bitmap to treat as transparent. By default, CLR_INVALID, indicating that the color currently set as the transparent color of the image should be used.

  • rectDest
    A reference to a RECT structure, identifying the destination.

  • xSrc
    The x-coordinate, in logical units, of the upper left corner of the source rectangle.

  • ySrc
    The y-coordinate, in logical units, of the upper left corner of the source rectangle.

  • nSrcWidth
    The width, in logical units, of the source rectangle.

  • nSrcHeight
    The height, in logical units, of the source rectangle.

  • rectSrc
    A reference to a RECT structure, identifying the source.

Return Value

TRUE if successful, otherwise FALSE.

Remarks

TransparentBlt is supported for source bitmaps of 4 bits per pixel and 8 bits per pixel. Use CImage::AlphaBlend to specify 32 bits-per-pixel bitmaps with transparency.

This method is applicable to Microsoft Windows 2000, Windows 98, and later systems. See TransparentBlt in the Windows SDK and CImage Limitations with Earlier Operating Systems for more detailed information.

Example

// Performs a transparent blit from the source image to the destination  
// image using the images' current transparency settings
BOOL TransparentBlt(CImage* pSrcImage, CImage* pDstImage, int xDest, int yDest,
   int nDestWidth, int nDestHeight)
{
   HDC hDstDC = NULL;
   BOOL bResult;

   if(pSrcImage == NULL || pDstImage == NULL)
   {
      // Invalid parameter 
      return FALSE;
   }

   // Obtain a DC to the destination image
   hDstDC = pDstImage->GetDC();

   // Perform the blit
   bResult = pSrcImage->TransparentBlt(hDstDC, xDest, yDest, nDestWidth, nDestHeight);

   // Release the destination DC
   pDstImage->ReleaseDC();

   return bResult;
}

Requirements

Header: atlimage.h

See Also

Reference

CImage Class

CImage::StretchBlt

CImage::MaskBlt

CImage::BitBlt