Difference between revisions of "DxConvertPixels"

From Multi Theft Auto: Wiki
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.)
 
<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>
 +
</section>
  
 
==Requirements==
 
==Requirements==
Line 28: Line 39:
 
==See Also==
 
==See Also==
 
{{Drawing_functions}}
 
{{Drawing_functions}}
[[Category:Needs Example]]
 

Revision as of 20:23, 27 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

Click to collapse [-]
Client

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