Skip to content

Format

typescript
RenderTexture.SetPixels(x, y, blockWidth, blockHeight, colors, mipLevel)

class: RenderTexture

Description

Get the pixel color of the block with a width of blockWidth and a height of blockHeight at the coordinates (x, y) in the upper right corner.

Parameters

param_nametypedescription
xnumberThe x-axis coordinate.
ynumberThe y-axis coordinate.
blockWidthnumberThe width of the block.
blockHeightnumberThe height of the block.
colorsColor[]An array of pixel colors for the block.
mipLevelnumber?The mipmap level.

Return

typedescription
void

Code Example

typescript
function Test() {
    try {
        let temp_texture = RenderTexture.GetTemporary(100, 100, RenderTextureFormat.Default, DepthType.Depth24Stencil8, AntiAliasingLevel.x8);
        let color_array:Color[] = new Array(60*60);
        for (let i = 0; i < color_array.length; ++i) {
            color_array[i] = Color.cyan;
        }
        texture.SetPixels(20, 20, 60, 60, color_array, 0);
        let color_array_test = texture.GetPixels(20, 20, 60, 60, 0);
    } catch (error) {
        Debug.Log(error);
    }
}