Class

# RGBSurface

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used for direct-color pixel manipulations. The <span class="title-ref">RGBSurface</span> property of a `Picture</api/graphics/picture>` object allows you to manipulate the picture at the pixel level. Can be used only for pictures created by the `Picture</api/graphics/picture>` constructor with no pixel depth or a depth of only 16 or 32.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                              | Parameters                                                                                                                                             | Returns                        | Shared |
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|--------|
| `FloodFill<rgbsurface.floodfill>` | x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`, FillColor As `Color</api/data_types/color>`                              |                                |        |
| `Pixel<rgbsurface.pixel>`         | x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`                                                                           | `Color</api/data_types/color>` |        |
|                                   | x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>` |                                |        |
| `Transform<rgbsurface.transform>` | map() As `Integer</api/data_types/integer>`                                                                                                            |                                |        |
|                                   | redMap() As `Integer</api/data_types/integer>`, greenMap() As `Integer</api/data_types/integer>`, blueMap() As `Integer</api/data_types/integer>`      |                                |        |

## Method descriptions

<div id="rgbsurface.floodfill">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RGBSurface.FloodFill

**FloodFill**(x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`, FillColor As `Color</api/data_types/color>`)

> Performs a "floodfill" (the action performed by a PaintBucket tool in an image editing program) on an <span class="title-ref">RGBSurface</span>.
>
> The pixel at *x*, *y* and all adjacent pixels of the same color are changed to the passed *FillColor*.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not currently supported for Android.
>
> </div>
>
> The following code uses the FloodFill method to paint an <span class="title-ref">RGBSurface</span> object in a random color. It is in the MouseDown event of a `DesktopCanvas</api/user_interface/desktop/desktopcanvas>` control. The variable p is a `Picture</api/graphics/picture>` object.
>
> ``` xojo
> Var randomColor As Color
> randomColor = Color.RGB(Rnd * 255, Rnd * 255, Rnd * 255) ' create random color
> p.RGBSurface.FloodFill(x, y, randomColor) ' fill the area with the color
> Me.Graphics.DrawPicture(p, 0, 0) ' repaint the canvas control
> ```

<div id="rgbsurface.pixel">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RGBSurface.Pixel

**Pixel**(x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`) As `Color</api/data_types/color>`

> Returns the `color</api/data_types/color>` of the object at location specified by the *x* and *y* parameters.
>
> This example replaces all the black pixels in a `Picture</api/graphics/picture>`, somePicture, with white:
>
> ``` xojo
> 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
>   Next
> Next
> ```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

**Pixel**(x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>`)

> The `color</api/data_types/color>` *value* is assigned to the location specified by the *x* and *y* parameters.

<div id="rgbsurface.transform">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RGBSurface.Transform

**Transform**(map() As `Integer</api/data_types/integer>`)

> Applies a one-to-one pixel transformation to all pixels of an <span class="title-ref">RGBSurface</span>.
>
> Each map parameter is an 256 element array of integers. The transformation works as follows: For each pixel, the pixel's RGB value is used as an index into the map arrays and the value found becomes the new R, G, or B value for the pixel.
>
> For example, if you set up a map such that map(i)=255-i, then calling Transform(Map) will invert the image.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not currently supported for Android.
>
> </div>
>
> The following example uses the Transform method to invert an image:
>
> ``` xojo
> Const kMaxMapOffset = 255
> Var map(kMaxMapOffset) As Integer
> For i As Integer = 0 To kMaxMapOffset
>   map(i) = kMaxMapOffset - i
> Next
> somePicture.RGBSurface.Transform(map)
> ```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

**Transform**(redMap() As `Integer</api/data_types/integer>`, greenMap() As `Integer</api/data_types/integer>`, blueMap() As `Integer</api/data_types/integer>`)

> Applies a one-to-one pixel transformation by primary color (red, green, blue) of an <span class="title-ref">RGBSurface</span>.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not currently supported for Android.
>
> </div>

## Notes

Pixel manipulations using the <span class="title-ref">RGBSurface</span> property are faster than the same manipulations using the `Graphics</api/graphics/graphics>` class methods.

32-bit <span class="title-ref">RGBSurface</span> objects are mapped to 24-bit objects on Windows.

<span class="title-ref">RGBSurface</span> supports alpha channels by taking them into account when rendering objects.

## Sample code

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

``` xojo
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
  Next
Next

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following example uses the FloodFill method to paint an <span class="title-ref">RGBSurface</span> object in a random color. You can put it in the Paint event handle of a Canvas.

``` xojo
' 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.

``` xojo
Const kMaxMapOffset = 255
Var 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)
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `RGBSurface<picture.rgbsurface>` property of the `Picture</api/graphics/picture>` object.

</div>
