Click to Rate and Give Feedback
MSDN
MSDN Library
Windows GDI
Bitmaps
Bitmap Reference
Bitmap Functions
 SetPixel
Windows GDI
SetPixel

The SetPixel function sets the pixel at the specified coordinates to the specified color.

COLORREF SetPixel(
  HDC hdc,           // handle to DC
  int X,             // x-coordinate of pixel
  int Y,             // y-coordinate of pixel
  COLORREF crColor   // pixel color
);

Parameters

hdc
[in] Handle to the device context.
X
[in] Specifies the x-coordinate, in logical units, of the point to be set.
Y
[in] Specifies the y-coordinate, in logical units, of the point to be set.
crColor
[in] Specifies the color to be used to paint the point. To create a COLORREF color value, use the RGB macro.

Return Values

If the function succeeds, the return value is the RGB value that the function sets the pixel to. This value may differ from the color specified by crColor; that occurs when an exact match for the specified color cannot be found.

If the function fails, the return value is 1.

Windows NT/2000/XP: To get extended error information, call GetLastError. This can be the following value.

Value Meaning
ERROR_INVALID_PARAMETER One or more input parameters are invalid.

Remarks

The function fails if the pixel coordinates lie outside of the current clipping region.

Not all devices support the SetPixel function. For more information, see GetDeviceCaps.

Requirements

  Windows NT/2000/XP/Vista: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Wingdi.h; include Windows.h.
  Library: Use Gdi32.lib.

See Also

Bitmaps Overview, Bitmap Functions, GetDeviceCaps, GetPixel, SetPixelV, COLORREF, RGB


Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker