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

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:

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

Last Reviewed: July 18, 1997