INF:_getpixel() Return Value Not Changed by _setbkcolor() Call

ID Number: Q67759

5.10 6.00 6.00a 6.00ax 7.00

MS-DOS

Summary:

In the sample program below, _getpixel() returns a 0 (zero). Setting

_setbkcolor() to any other color has no effect on the return value

from _getpixel().

More Information:

The _getpixel() function is documented as returning a color index for

a specific pixel. In the example program, there are no colors on the

screen except the background color (color index 0). When the call to

_setbkcolor() is made, the color mapped to index 0 is changed;

however, the color index for the pixel is not changed. Therefore,

_getpixel() still returns 0. This same behavior is exhibited when

using the _remappallette() function on index 0 and the

_remapallpallette() function.

To change the color index at a particular point on the screen, first

call the _setcolor() function with the desired color index, then use

one of the graphics drawing functions, for example, _floodfill(),

_setpixel(), and so forth.

Sample Code

-----------

// Note: C 5.1 doesn't 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.0 6.00 6.0a 6.00a 6.0ax 6.00ax 2.0 2.00

2.01 2.5 2.50 2.51