PRB: Bitmap Displays Upside Down Using StretchDIBits (151920)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0, when used with:
    • Microsoft Windows NT Server 3.51
    • Microsoft Windows NT Workstation 3.51
    • Microsoft Windows 95

This article was previously published under Q151920

SYMPTOMS

Calling StretchDIBits on a DIB causes it to display upside down.

CAUSE

Two situations could cause a bitmap to display upside down in Win32:
  1. The signs of the cxSrc and cxDest parameters differ. The documentation for StretchDIBits states that the function creates a mirror image of a bitmap along the x-axis if the signs of the cxSrc and cxDest parameters differ. Whether intentional or unintentional, this could cause a bitmap to display upside down.
  2. The sign of the biHeight value in the BITMAPINFOHEADER does not correctly reflect how the bitmap bits are stored in the DIB file. In Win16, all DIBs are stored bottom-up, with the bottom-most scan line stored first in the DIB file. In Win32, DIBs may also be stored top-down, with the top-most scan line stored first. Top-down DIBs are denoted by a negative biHeight value in the BITMAPINFOHEADER structure; bottom-up DIBS are denoted by a positive biHeight value:
       DIB stored as      Should have a biHeight value of
       -------------      -------------------------------
       top-down           negative
       bottom-up          positive
    						
Make sure the biHeight value is appropriately set as positive or negative, depending on how the bitmap bits were stored in the DIB file. A mismatch in the way this value is set could result to an upside down bitmap because the DIB engine interprets the bits incorrectly. For example, a positive biHeight value for a DIB stored as top-down should cause a bitmap to display upside down.

STATUS

This behavior is by design.

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbprb KB151920