Sets the pixel at the specified coordinates to the specified color.
BOOL GdiSetPixel(
HDC hdc,
int x,
int y,
COLORREF color
);
RGB(0,0,0), or a system color value.
If the function succeeds, the return value is a nonzero value. If the function fails, the return value is zero.
This example draws a red pixel at coordinates (50, 75) on the specified device context.
BOOL bSuccess = GdiSetPixel(hdc, 50, 75, RGB(255, 0, 0));
if (!bSuccess) {
// Handle error
}
To draw a pixel, the GDI function GdiSetPixel is used. The function takes a handle to the device context (hdc), the x and y coordinates of the pixel, and the desired color as parameters. The color is specified using the COLORREF data type, which can be created using the RGB macro.
It is important to note that the actual pixel color may be dithered if the device's color palette does not support the exact color specified. This function is a fundamental building block for many GDI drawing operations.
For optimized pixel setting operations, consider using SetPixelV which does not return the previous pixel color, or platform-specific drawing functions for better performance.