RGBSurface

From Xojo Documentation

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 a pixel depth of 16 or 32.

Methods
FloodFill Transform
Pixel Transform

Notes

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.

Examples

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.

Dim surf As RGBSurface = somePicture.RGBSurface
Dim lastX As Integer = somePicture.Width - 1
Dim 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
Next
Next

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
Dim randomColor As Color
randomColor = 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
Dim map(kMaxMapOffset) As Integer
For i As Integer = 0 To kMaxMapOffset
map(i) = kMaxMapOffset - i
Next
somePicture.RGBSurface.Transform(map)

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

See Also

RGBSurface property of the Picture object.