Click to Rate and Give Feedback
MSDN
MSDN Library
Windows GDI
Bitmaps
Bitmap Reference
Bitmap Functions
 StretchDIBits
Windows GDI
StretchDIBits

The StretchDIBits function copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle. If the destination rectangle is larger than the source rectangle, this function stretches the rows and columns of color data to fit the destination rectangle. If the destination rectangle is smaller than the source rectangle, this function compresses the rows and columns by using the specified raster operation.

Windows 98/Me, Windows 2000/XP: StretchDIBits has been extended to allow a JPEG or PNG image to be passed as the source image.

int StretchDIBits(
  HDC hdc,                      // handle to DC
  int XDest,                    // x-coord of destination upper-left corner
  int YDest,                    // y-coord of destination upper-left corner
  int nDestWidth,               // width of destination rectangle
  int nDestHeight,              // height of destination rectangle
  int XSrc,                     // x-coord of source upper-left corner
  int YSrc,                     // y-coord of source upper-left corner
  int nSrcWidth,                // width of source rectangle
  int nSrcHeight,               // height of source rectangle
  CONST VOID *lpBits,           // bitmap bits
  CONST BITMAPINFO *lpBitsInfo, // bitmap data
  UINT iUsage,                  // usage options
  DWORD dwRop                   // raster operation code
);

Parameters

hdc
[in] Handle to the destination device context.
XDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
YDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nDestWidth
[in] Specifies the width, in logical units, of the destination rectangle.
nDestHeight
[in] Specifies the height, in logical units, of the destination rectangle.
XSrc
[in] Specifies the x-coordinate, in pixels, of the source rectangle in the DIB.
YSrc
[in] Specifies the y-coordinate, in pixels, of the source rectangle in the DIB.
nSrcWidth
[in] Specifies the width, in pixels, of the source rectangle in the DIB.
nSrcHeight
[in] Specifies the height, in pixels, of the source rectangle in the DIB.
lpBits
[in] Pointer to the DIB bits, which are stored as an array of bytes. For more information, see the Remarks section.
lpBitsInfo
[in] Pointer to a BITMAPINFO structure that contains information about the DIB.
iUsage
[in] Specifies whether the bmiColors member of the BITMAPINFO structure was provided and, if so, whether bmiColors contains explicit red, green, blue (RGB) values or indexes. The iUsage parameter must be one of the following values.
ValueMeaning
DIB_PAL_COLORSThe array contains 16-bit indexes into the logical palette of the source device context.
DIB_RGB_COLORSThe color table contains literal RGB values.

For more information, see the Remarks section.

dwRop
[in] Specifies how the source pixels, the destination device context's current brush, and the destination pixels are to be combined to form the new image. For more information, see the following Remarks section.

Return Values

If the function succeeds, the return value is the number of scan lines copied.

If the function fails, the return value is GDI_ERROR.

Windows 98/Me, Windows 2000/XP: If the driver cannot support the JPEG or PNG file image passed to StretchDIBits, the function will fail and return GDI_ERROR. If failure does occur, the application must fall back on its own JPEG or PNG support to decompress the image into a bitmap, and then pass the bitmap to StretchDIBits.

Remarks

The origin of a bottom-up DIB is the bottom-left corner; the origin of a top-down DIB is the upper-left corner.

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

Windows 98/Me, Windows 2000/XP: This function allows a JPEG or PNG image to be passed as the source image. How each parameter is used remains the same, except :

  • If the biCompression member of BITMAPINFOHEADER is BI_JPEG or BI_PNG, lpBits points to a buffer containing a JPEG or PNG image, respectively. The biSizeImage member of the BITMAPINFOHEADER structure specifies the size of the buffer. The iUsage parameter must be set to DIB_RGB_COLORS. The dwRop parameter must be set to SRCCOPY.
  • To ensure proper metafile spooling while printing, applications must call the CHECKJPEGFORMAT or CHECKPNGFORMAT escape to verify that the printer recognizes the JPEG or PNG image, respectively, before calling StretchDIBits.

ICM: Color management is performed. The color profile of the current device context is used as the source color space profile and the sRGB space is used.

Example Code

For an example, see Sizing a JPEG or PNG Image.

Requirements

  Windows NT/2000/XP/Vista: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Wingdi.h; include Windows.h.
  Library: Use Gdi32.lib.

See Also

Bitmaps Overview, Bitmap Functions, SetMapMode, SetStretchBltMode, BITMAPINFO


Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker