DxConvertPixels: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client function}} __NOTOC__ This function converts pixels from one format to another. ==Syntax== <syntaxhighlight lang="lua"> string newPixels = dxConvertPixels( string pixels, string newFo...")
 
(Remove obsolete Requirements section)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__
__NOTOC__
This function converts pixels from one format to another.
This function converts [[Texture_pixels|pixels]] from one format to another.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string newPixels = dxConvertPixels( string pixels, string newFormat [, int quality ] )
string dxConvertPixels ( string pixels, string newFormat [, int quality = 80 ] )
</syntaxhighlight>  
</syntaxhighlight>  


Line 19: Line 19:


==Example==  
==Example==  
The code opens an image, read its pixels, convert the pixels to PNG, and then save it. (You can use [http://i1325.photobucket.com/albums/u630/Tourmalinelisa2/128x128.jpg this] image to test.)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
TODO
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)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[hu:dxConvertPixels]]

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