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

' 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

Related Functions

GetPixel, SetPixel

Category

Bitmaps

Back to the index.


Last Modified: September 3, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information

Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/s/setpixelv.html