DxConvertPixels: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
Line 31: Line 31:
end)
end)
</syntaxhighlight>
</syntaxhighlight>
==Requirements==
{{Requirements|n/a|1.3|}}


==See Also==
==See Also==

Latest revision as of 15:42, 7 November 2024

This function converts pixels from one format to another.

Syntax

string dxConvertPixels ( string pixels, string newFormat [, int quality = 80 ] )

Required Arguments

  • pixels : The pixels to convert the format of
  • newFormat : The new format required ('plain' or 'png' or 'jpeg')

Optional Arguments

  • quality : The quality of the returned pixels if the new format is 'jpeg'

Returns

Returns a copy of the pixels in the new format, or false if invalid arguments were passed to the function.

Example

The code opens an image, read its pixels, convert the pixels to PNG, and then save it. (You can use this image to test.)

addEventHandler('onClientResourceStart', resourceRoot, function()
  local img = fileOpen('img.jpg')
  local pixels = fileRead(img, fileGetSize(img))
  local pngPixels = dxConvertPixels(pixels, 'png')
  local newImg = fileCreate('img.png')
  fileWrite(newImg, pngPixels)
  fileClose(newImg)
  fileClose(img)
end)

See Also