Graphics.Pixel

From Xojo Documentation

Property (As Color )
aGraphics.Pixel(X as Integer, Y as Integer) = newColorValue
or
ColorValue = aGraphics.Pixel(X as Integer, Y as Integer)

Supported for all project types and targets.

Used to get and set the color of a particular pixel. You can do the same thing with RGBSurface.Pixel which is significantly faster.

Notes

Pixel has been updated to properly support alpha channels by taking them into account when rendering them. Additionally, Pixel with always return Nil for pointers with alpha channels. For pictures without alpha channels, the mask functionality will continue to work.

macOS Note

In macOS builds, you can read from Graphics.Pixel only for Graphics objects obtained from a Picture. Doing so from other Graphics objects will result in an UnsupportedOperationException. You can however assign a value to Graphics.Pixel for a Graphics object obtained from any object.

Examples

This example assigns the color of a particular pixel in a Canvas control to a variable.

Dim c As Color
c = Canvas1.Graphics.Pixel(10, 10)

This example sets a particular pixel of a Canvas control to a specific RGB value.

Canvas1.Graphics.Pixel(10, 10) = RGB(100, 105, 225)

See Also

RGBSurface class.