dxGetTexturePixels
Client
Reads an image's pixels and hands them to a function, a few frames later.
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
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 MTAMTA returns the pixels right away. MYMP hands them to a function, since reading from the GPU takes a few frames.