PRB: _getpixel() Return Value Unchanged After _setbkcolor()

Last reviewed: July 17, 1997
Article ID: Q67759
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                      | WINDOWS
kbprg kbprb

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

In an MS-DOS application, the _getpixel() function always returns the value zero (0) when the specified pixel is drawn in the background color. Using the _setbkcolor() function to change the color of the background does not affect the return value from _getpixel().

CAUSE

The _getpixel() function returns the color index for the specified pixel, not the value for the color mapped to a particular color index. The background color in graphics mode is always mapped to palette entry 0.

RESOLUTION

If the application changes the color index for a particular point on the screen, the _getpixel() function returns a different value. Specify the desired color index with the _setcolor() function and call one of the graphics drawing functions, such as _floodfill(), _setpixel(), and so on.

MORE INFORMATION

The following code example demonstrates this situation.

Sample Code

/* Compile options needed: none
 * Link options needed: GRAPHICS.LIB
 */

// Note: C 5.1 does not support _MAXRESMODE

#include <graph.h>
#include <stdio.h>

void main(void)
{
   short xvar = 100, yvar = 100, result1 = 0, result2 = 0;
   _setvideomode(_MAXRESMODE);
   result1 = _getpixel(xvar, yvar);
   _setbkcolor(_BLUE);
   result2 = _getpixel(xvar, yvar);
   _setvideomode(_DEFAULTMODE);
   printf("Before _setbkcolor - %d\n", result1);
   printf("After _setbkcolor  - %d\n", result2);
}


Additional reference words: 6.00 6.00a 6.00ax 7.00 1.00 1.50
KBCategory: kbprg kbprb
KBSubcategory: CRTIss GraphicsIss
Keywords : kb16bitonly


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: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.