# dxGetTexturePixels (Client)

> Reads an image's pixels and hands them to a function, a few frames later.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Screen drawing
- **URL**: https://wiki.mymp.gg/en/dxGetTexturePixels

## Syntax

```lua
bool dxGetTexturePixels(texture|dui texture, function callback [, string format = plain, string textureFormat = unknown, bool mipmaps = true, int x, y = 0, 0, int width, height = 0, 0])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `texture` | `texture\|dui` | The image: a texture, render target, screen source or dui. A txd texture works too. |
| `format` | `string` | Format: `plain`, `png`, `jpeg` or `dds`. *(default: `plain`)* |
| `textureFormat` | `string` | For `dds`: `unknown` (the image's own), `argb`, `xrgb`, `rgb`, `dxt1`, `dxt2`, `dxt3`, `dxt4` or `dxt5`. Only allowed after `format`. *(default: `unknown`)* |
| `mipmaps` | `bool` | For `dds`: generate mipmaps. Only allowed after `format`. *(default: `true`)* |
| `x, y` | `int` | Top-left corner of the area read, in pixels. A vec2 also works. *(default: `0, 0`)* |
| `width, height` | `int` | Size of the area read. With a height of 0, the whole image is read. A vec2 also works. *(default: `0, 0`)* |
| `callback` | `function` | Receives the pixels as a string, or `false` when the read failed. |

## Returns

`true` when the read started, `false` when the image has no content yet.

A leading number (MTA's surface index) is accepted and ignored. `plain` pixels are 4 bytes per pixel (blue, green, red, alpha), row by row, followed by the width and the height in 2 bytes each.

## Example

```lua
local target = dxCreateRenderTarget(256, 256, true)

dxGetTexturePixels(target, "png", function(pixels)
    if not pixels then return end
    local file = fileCreate("snapshot.png")
    fileWrite(file, pixels)
    fileClose(file)
end)
```

### Coming from MTA

MTA returns the pixels right away. MYMP hands them to a function, since reading from the GPU takes a few frames.

## See also

- [dxSetTexturePixels (Client)](https://wiki.mymp.gg/en/dxSetTexturePixels.md): Writes pixels into a texture made by a script or into a render target.
- [dxConvertPixels (Client)](https://wiki.mymp.gg/en/dxConvertPixels.md): Converts an image held in a string to another format, in the background, and hands the result to a function.
- [dxGetPixelColor (Client)](https://wiki.mymp.gg/en/dxGetPixelColor.md): Reads the colour of one pixel of a plain image.
- [engineGetTxdTexture (Client)](https://wiki.mymp.gg/en/engineGetTxdTexture.md): Gives a texture element that shows what a txd shows under a texture name, to draw it or use it as a source.
