StretchBlt

Syntax

BOOL StretchBlt(hDestDC,X,Y,nWidth,nHeight,hSrcDC,XSrc,YSrc,nSrcWidth,nSrcHeight,dwRop)

This function moves a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle. The StretchBlt function uses the stretching mode of the destination device context (set by the SetStretchBltMode function) to determine how to stretch or compress the bitmap.

StretchBlt moves the bitmap from the source device given by the hSrcDC parameter to the destination device given by the hDestDC parameter. The XSrc, YSrc, nSrcWidth, and nSrcHeight parameters define the origin and dimensions of the source rectangle. The X, Y, nWidth, and nHeight parameters give the origin and dimensions of the destination rectangle. The raster operation specified by the dwRop parameter defines how the source bitmap and the bits already on the destination device are combined.

StretchBlt creates a mirror image of a bitmap if the signs of the nSrcWidth and nWidth or nSrcHeight and nHeight parameters differ. If nSrcWidth and nWidth have different signs, the function creates a mirror image of the bitmap along the x-axis. If nSrcHeight and nHeight have different signs, the function creates a mirror image of the bitmap along the y-axis.

Parameter Type/Description  

hDestDC HDC Identifies the device context to receive the bitmap.  
X int Specifies the logical x-coordinate of the upper-left corner of the destination rectangle.  
Y int Specifies the logical y-coordinate of the upper-left corner of the destination rectangle.  
nWidth int Specifies the width (in logical units) of the destination rectangle.  
nHeight int Specifies the height (in logical units) of the destination rectangle.  
hSrcDC HDC Identifies the device context that contains the source bitmap.  
XSrc int Specifies the logical x-coordinate of the upper-left corner of the source rectangle.  
YSrc int Specifies the logical y-coordinate of the upper-left corner of the source rectangle.  
nSrcWidth int Specifies the width (in logical units) of the source rectangle.  
   
nSrcHeight int Specifies the height (in logical units) of the source rectangle.  
dwRop DWORD Specifies the raster operation to be performed. Raster operation codes define how GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. For a list of raster-operation codes, see the BitBlt function, earlier in this chapter.  

Return Value

The return value specifies whether the bitmap is drawn. It is nonzero if the bitmap is drawn. Otherwise, it is zero.

Comments

StretchBlt stretches or compresses the source bitmap in memory, then copies the result to the destination. If a pattern is to be merged with the result, it is not merged until the stretched source bitmap is copied to the destination.

If a brush is used, it is the selected brush in the destination device context.

The destination coordinates are transformed according to the destination device context; the source coordinates are transformed according to the source device context.

If destination, source, and pattern bitmaps do not have the same color format, StretchBlt converts the source and pattern bitmaps to match the destination bitmaps. The foreground and background colors of the destination are used in the conversion.

If StretchBlt must convert a monochrome bitmap to color, it sets white bits (1) to background color and black bits (0) to foreground color. To convert color to monochrome, it sets pixels that match the background color to white (1), and sets all other pixels to black (0). The foreground and background colors of the device context with color are used.

Not all devices support the StretchBlt function. For more information, see the RC_BITBLT capability in the GetDeviceCaps function, earlier in this chapter.