2 out of 4 rated this helpful Rate this topic

GetPixel function

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

Syntax

COLORREF GetPixel(
  __in  HDC hdc,
  __in  int nXPos,
  __in  int nYPos
);

Parameters

hdc [in]

A handle to the device context.

nXPos [in]

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

nYPos [in]

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

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wingdi.h (include Windows.h)

Library

Gdi32.lib

DLL

Gdi32.dll

See also

Bitmaps Overview
Bitmap Functions
COLORREF
GetDeviceCaps
SetPixel

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
Not concurrently safe
Despite it's read-only, if used concurrently for the same DC the returning values are often incorrect.