Difference between revisions of "DxConvertPixels"

From Multi Theft Auto: Wiki
m (No point of the section as it's already a client function)
Line 19: Line 19:
  
 
==Example==  
 
==Example==  
<section name="Client" class="client" show="true">
 
 
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.)
 
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">
Line 32: Line 31:
 
end)
 
end)
 
</syntaxhighlight>
 
</syntaxhighlight>
</section>
 
  
 
==Requirements==
 
==Requirements==

Revision as of 18:26, 28 September 2013

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)

Requirements

Minimum supported server n/a
Minimum supported client 1.3

Note: Using this function requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3" />

See Also

BETA: FROM VERSION 1.5.7 r19626 ONWARDS
BETA: FROM VERSION 1.5.7 r20328 ONWARDS
BETA: FROM VERSION 1.5.7 r20447 ONWARDS