From Xojo Documentation

Revision as of 20:46, 18 February 2022 by Gperlman (talk | contribs) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)

Used for direct-color pixel manipulations. The RGBSurface property of a Picture object allows you to manipulate the picture at the pixel level. Can be used only for pictures created by the Picture constructor with no pixel depth or a depth of only 16 or 32.

FloodFill Pixel Transform


Pixel manipulations using the RGBSurface property are faster than the same manipulations using the Graphics class methods.

32-bit RGBSurface objects are mapped to 24-bit objects on Windows.

RGBSurface supports alpha channels by taking them into account when rendering objects.


This example replaces all the black pixels in a Picture, somePicture, with white. Put it in the Paint event handler of a Canvas and reference a picture you have added to the project.

Var surf As RGBSurface = somePicture.RGBSurface
Var lastX As Integer = somePicture.Width - 1
Var lastY As Integer = somePicture.Height - 1
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
If surf.Pixel(x, y) = &c000000 Then
surf.Pixel(x, y) = &cFFFFFF
End if

g.DrawPicture(somePicture, 0, 0, somePicture.Width, somePicture.Height)

The following example uses the FloodFill method to paint an RGBSurface object in a random color. You can put it in the Paint event handle of a Canvas.

// Create a random color
Var randomColor As Color
randomColor = Color.RGB(Rnd * 255, Rnd * 255, Rnd * 255) //create random color

// Starting in the top left, fill the picture with the color
somePicture.RGBSurface.FloodFill(0, 0, randomColor)

// Display the picture
g.DrawPicture(somePicture, 0, 0)

The following example uses the Transform method to invert an image. You can put it in the Paint event handle of a Canvas.

Const kMaxMapOffset = 255
Var map(kMaxMapOffset) As Integer
For i As Integer = 0 To kMaxMapOffset
map(i) = kMaxMapOffset - i

// Display the picture
g.DrawPicture(somePicture, 0, 0)

See Also

RGBSurface property of the Picture object.