GetPixel function

The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.

Syntax

COLORREF GetPixel(
  HDC hdc,
  int x,
  int y
);

Parameters

hdc

A handle to the device context.

x

The x-coordinate, in logical units, of the pixel to be examined.

y

The y-coordinate, in logical units, of the pixel to be examined.

Return Value

The return value is the COLORREF value that specifies the RGB of the pixel. If the pixel is outside of the current clipping region, the return value is CLR_INVALID (0xFFFFFFFF defined in Wingdi.h).

Remarks

The pixel must be within the boundaries of the current clipping region.

Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function.

A bitmap must be selected within the device context, otherwise, CLR_INVALID is returned on all pixels.

Requirements

   
Windows version Windows 2000 Professional [desktop apps only] Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll

See Also

Bitmap Functions

Bitmaps Overview

COLORREF

GetDeviceCaps

SetPixel