# dxConvertPixels (Client)

> Converts an image held in a string to another format, in the background, and hands the result to a function.

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

## Syntax

```lua
bool dxConvertPixels(string pixels, string format, function callback [, int quality = 80])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `pixels` | `string` | The pixels. |
| `format` | `string` | Target format: `plain`, `png` or `jpeg`. |
| `quality` | `int` | `jpeg` quality, from 0 to 100. *(default: `80`)* |
| `callback` | `function` | Receives the converted pixels, or `false` when the conversion failed. |

## Returns

`true` when the conversion started. `false` when the source format was not recognised or the conversion is to or from `dds`.

## Example

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

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

### Coming from MTA

MTA returns the result right away. MYMP hands it to a function, since the conversion runs on a worker thread.

## See also

- [dxGetTexturePixels (Client)](https://wiki.mymp.gg/en/dxGetTexturePixels.md): Reads an image's pixels and hands them to a function, a few frames later.
- [dxGetPixelsFormat (Client)](https://wiki.mymp.gg/en/dxGetPixelsFormat.md): Detects the format of an image held in a string.
- [dxSetTexturePixels (Client)](https://wiki.mymp.gg/en/dxSetTexturePixels.md): Writes pixels into a texture made by a script or into a render target.
