Difference between revisions of "ImageData:encode"
(Updated for 0.10.0) |
m (→Draw a circle in a canvas, save it in file and display it on screen: Small wording changes and fixes.) |
||
(12 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | Encodes the ImageData and optionally writes it to the save directory. | + | Encodes the ImageData to a file format and optionally writes it to the [[love.filesystem|save directory]]. |
== Function == | == Function == | ||
Line 8: | Line 8: | ||
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
− | {{param| | + | {{param|ImageEncodeFormat|format|The format to encode the image as.}} |
{{param|string|filename (nil)|The filename to write the file to. If nil, no file will be written but the FileData will still be returned.}} | {{param|string|filename (nil)|The filename to write the file to. If nil, no file will be written but the FileData will still be returned.}} | ||
=== Returns === | === Returns === | ||
Line 14: | Line 14: | ||
== Function == | == Function == | ||
− | {{ | + | {{newinoldin|[[0.8.0]]|080|[[0.10.0]]|100|type=variant}} |
− | |||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 26: | Line 25: | ||
== Function == | == Function == | ||
− | {{ | + | {{newinoldin|[[0.8.0]]|080|[[0.10.0]]|100|type=variant}} |
− | |||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 34: | Line 32: | ||
=== Arguments === | === Arguments === | ||
{{param|string|outFile|Name of a file to write encoded data to.}} | {{param|string|outFile|Name of a file to write encoded data to.}} | ||
− | {{param| | + | {{param|ImageEncodeFormat|format|The format to encode the image in.}} |
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
Line 45: | Line 43: | ||
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
− | {{param| | + | {{param|ImageEncodeFormat|format|The format to encode the image in.}} |
=== Returns === | === Returns === | ||
{{param|Data|data|The encoded image data.}} | {{param|Data|data|The encoded image data.}} | ||
+ | |||
+ | == Examples == | ||
+ | === Draw a circle to a canvas and save it to a file === | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | canvas = love.graphics.newCanvas(800, 600) | ||
+ | |||
+ | love.graphics.setCanvas(canvas) | ||
+ | love.graphics.circle("fill", 200,200, 100) | ||
+ | love.graphics.setCanvas() -- The canvas must not be active when we call canvas:newImageData(). | ||
+ | |||
+ | local imagedata = canvas:newImageData() | ||
+ | imagedata:encode("tga", "test.tga") | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.draw(canvas) -- Draw canvas on screen. | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | == User Notes == | ||
+ | * If you want the file to have an extension when saved add it in the file name. Example : <source lang="lua">image:encode("png","aPngImage.png")</source> | ||
== See Also == | == See Also == | ||
* [[parent::ImageData]] | * [[parent::ImageData]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description=Encodes ImageData.}} | + | {{#set:Description=Encodes the ImageData to a file format and optionally writes it to the [[love.filesystem|save directory]].}} |
{{#set:Since=000}} | {{#set:Since=000}} | ||
+ | |||
== Other Languages == | == Other Languages == | ||
{{i18n|ImageData:encode}} | {{i18n|ImageData:encode}} |
Latest revision as of 19:16, 3 June 2022
Encodes the ImageData to a file format and optionally writes it to the save directory.
Contents
Function
Available since LÖVE 0.10.0 |
This variant is not supported in earlier versions. |
Synopsis
filedata = ImageData:encode( format, filename )
Arguments
ImageEncodeFormat format
- The format to encode the image as.
string filename (nil)
- The filename to write the file to. If nil, no file will be written but the FileData will still be returned.
Returns
FileData filedata
- The encoded image as a new FileData object.
Function
Available since LÖVE 0.8.0 and removed in LÖVE 0.10.0 |
This variant is not supported in earlier or later versions. |
Synopsis
ImageData:encode( outFile )
Arguments
string outFile
- Name of a file to write encoded data to. The format will be automatically deduced from the file extension.
Returns
Nothing.
Function
Available since LÖVE 0.8.0 and removed in LÖVE 0.10.0 |
This variant is not supported in earlier or later versions. |
Synopsis
ImageData:encode( outFile, format )
Arguments
string outFile
- Name of a file to write encoded data to.
ImageEncodeFormat format
- The format to encode the image in.
Returns
Nothing.
Function
Removed in LÖVE 0.8.0 |
This variant is not supported in that and later versions. |
Synopsis
data = ImageData:encode( format )
Arguments
ImageEncodeFormat format
- The format to encode the image in.
Returns
Data data
- The encoded image data.
Examples
Draw a circle to a canvas and save it to a file
function love.load()
canvas = love.graphics.newCanvas(800, 600)
love.graphics.setCanvas(canvas)
love.graphics.circle("fill", 200,200, 100)
love.graphics.setCanvas() -- The canvas must not be active when we call canvas:newImageData().
local imagedata = canvas:newImageData()
imagedata:encode("tga", "test.tga")
end
function love.draw()
love.graphics.draw(canvas) -- Draw canvas on screen.
end
User Notes
- If you want the file to have an extension when saved add it in the file name. Example :
image:encode("png","aPngImage.png")
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info