SetPixelV Function

Declare Function SetPixelV Lib "gdi32.dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

Platforms

Description & Usage

SetPixelV sets the color of a single pixel on a device. Because of color matching on the device, sometimes the color actually used on the device may differ from the color specified by the function. The function will fail if the pixel specified is not visible or out of range when the function is called. This function executes slightly more quickly than SetPixel because this function does not need to return the actual color used by the device.

Return Value

If an error occured, the function returns 0 (call GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

hdc
A handle to a device context to the device to color a pixel of.
X
The x-coordinate of the pixel to color.
Y
The y-coordinate of the pixel to color.
crColor
The RGB value of the color to set the pixel to.

Example

' This code is licensed according to the terms and conditions listed here.

' Randomly color all the pixels in window Form1.  This example
' gets the rectangle of Form1 and iterates through all the points
' (pixels) inside of it.
Dim winrect As RECT  ' rectangle of window Form1
Dim rgbval As Long  ' RGB value of the randomly selected color
Dim x As Long, y As Long  ' counters for x and y coordinates
Dim retval As Long  ' return value

' Get the rectangle of window Form1.
retval = GetWindowRect(Form1.hWnd, winrect)

' Loop through each pixel within Form1.
For y = 0 To winrect.bottom - winrect.top
  For x = 0 To winrect.right - winrect.left
    ' Select a random color by choosing a value between 0 and 255
    ' inclusive for each component of the color.
    rgbval = RGB(Int(256 * Rnd), Int(256 * Rnd), Int(256 * Rnd))
    ' Set the pixel to the color above.
    retval = SetPixelV(Form1.hDC, x, y, rgbval)
  Next x
Next y

See Also

GetPixel, SetPixel

Category

Bitmaps

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: September 3, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/setpixelv.html