PRB: Bitmap Displays Upside Down Using StretchDIBits

Last reviewed: May 31, 1996
Article ID: Q151920
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) for:

        - Windows NT, version 3.51
        - Windows 95
    

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 will interpret 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.


Additional reference words: 4.00 3.51 inverted reverse
KBCategory: kbgraphic kbprb
KBSubcategory: GdiBmp



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 31, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.