ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. dxGetTexturePixels

Function

dxGetTexturePixels

Reads the pixels of a texture, a render target or a screen source in plain, png or jpeg format, whole or from a section (x, y, width, height). For example for a screenshot.

Syntax

string dxGetTexturePixels(element texture [, int surfaceIndex, string pixelsFormat = "plain", int x, y, width, height])

Arguments

surfaceIndexint, optional
Surface index (compatibility with existing scripts).
textureelement
The texture.
pixelsFormatstring, optional = "plain"
"plain", "png", "jpeg".
x, y, width, heightint, optional
A section.Different type in MTA:SA: string textureFormat = "unknown"

Differences from MTA:SA

  • Arguments in a different colour differ from MTA:SA.
  • These MTA:SA arguments are not here: int width = 0, int height = 0

In MTA:SA

dxGetTexturePixels(int surfaceIndex = 0, texture texture, string pixelsFormat = "plain", string textureFormat = "unknown", bool mipmaps, int x = 0, int y = 0, int width = 0, int height = 0)

Returns

Pixels or false.

Example

local screen = dxCreateScreenSource(1280, 720)
bindKey("F12", "down", function()
    dxUpdateScreenSource(screen)
    setTimer(function()
        local png = dxGetTexturePixels(screen, "png")
        if png then
            local f = fileCreate("zrzut.png")
            fileWrite(f, png)
            fileClose(f)
        end
    end, 100, 1)
end)

See also