Difference between revisions of "ImageData"
m |
|||
(21 intermediate revisions by 9 users not shown) | |||
Line 2: | Line 2: | ||
You can't draw ImageData directly to screen. See [[Image]] for that. | You can't draw ImageData directly to screen. See [[Image]] for that. | ||
+ | == Constructors == | ||
+ | {{#ask: [[Category:Functions]] [[Constructs::ImageData]] [[Concept:Current]] | ||
+ | | headers=hide | ||
+ | | default=None. | ||
+ | | format=template | ||
+ | | template=ListingFields | ||
+ | | introtemplate=ListingIntro | ||
+ | | outrotemplate=ListingOutro | ||
+ | | ?Description | ||
+ | | ?PrettySince | ||
+ | | ?PrettyRemoved | ||
+ | }} | ||
== Functions == | == Functions == | ||
− | {{#ask: [[Category:Functions]] [[parent::ImageData]] | + | {{#ask: [[Category:Functions]] [[parent::ImageData||Data||Object]] [[Concept:Current]] |
| headers=hide | | headers=hide | ||
+ | | format=template | ||
+ | | template=ListingFields | ||
+ | | introtemplate=ListingIntro | ||
+ | | outrotemplate=ListingOutro | ||
| ?Description | | ?Description | ||
+ | | ?PrettySince | ||
+ | | ?PrettyRemoved | ||
}} | }} | ||
− | {{#ask: [[Category: | + | == Enums == |
+ | {{#ask: [[Category:Enums]] [[parent::ImageData]] [[Concept:Current]] | ||
| headers=hide | | headers=hide | ||
+ | | format=template | ||
+ | | template=ListingFields | ||
+ | | introtemplate=ListingIntro | ||
+ | | outrotemplate=ListingOutro | ||
| ?Description | | ?Description | ||
+ | | ?PrettySince | ||
+ | | ?PrettyRemoved | ||
}} | }} | ||
+ | |||
+ | == Supertypes == | ||
+ | * [[parent::Data]] | ||
+ | * [[parent::Object]] | ||
+ | |||
== Examples == | == Examples == | ||
− | === | + | |
+ | === Load map from image === | ||
+ | (Note that this example creates a ''lot'' of tables.) | ||
<source lang="lua"> | <source lang="lua"> | ||
− | + | local filename = "image.png" | |
− | + | local imageData = love.image.newImageData(filename) | |
− | + | local width, height = imageData:getDimensions() | |
− | + | local map = {} | |
− | + | ||
− | + | for y = 1, height do | |
− | + | map[y] = {} | |
− | + | for x = 1, width do | |
− | + | local r, g, b, a = imageData:getPixel(x-1, y-1) | |
− | + | map[y][x] = {r, g, b, a} | |
− | local | ||
− | |||
− | |||
end | end | ||
− | |||
− | |||
end | end | ||
+ | |||
</source> | </source> | ||
− | + | ||
− | |||
== See Also == | == See Also == | ||
* [[parent::love.image]] | * [[parent::love.image]] | ||
* [[Image]] | * [[Image]] | ||
[[Category:Types]] | [[Category:Types]] | ||
− | {{#set:Description=Raw (decoded) image data. | + | {{#set:Description=Raw (decoded) image data.}} |
− | }} | + | {{#set:Since=000}} |
== Other Languages == | == Other Languages == | ||
{{i18n|ImageData}} | {{i18n|ImageData}} |
Latest revision as of 18:27, 18 February 2024
Raw (decoded) image data.
You can't draw ImageData directly to screen. See Image for that.
Contents
Constructors
Canvas:newImageData | Generates ImageData from the contents of the Canvas. | 0.10.0 | |
love.graphics.newScreenshot | Creates a screenshot and returns the ImageData. | 11.0 | |
love.image.newImageData | Creates a new ImageData object. |
Functions
Data:clone | Creates a new copy of the Data object. | 11.0 | |
Data:getFFIPointer | Gets an FFI pointer to the Data. | 11.3 | |
Data:getPointer | Gets a pointer to the Data. | ||
Data:getSize | Gets the Data's size in bytes. | ||
Data:getString | Gets the full Data as a string. | 0.9.0 | |
ImageData:encode | Encodes the ImageData to a file format and optionally writes it to the save directory. | ||
ImageData:getDimensions | Gets the width and height of the ImageData in pixels. | 0.9.0 | |
ImageData:getFormat | Gets the pixel format of the ImageData. | 11.0 | |
ImageData:getHeight | Gets the height of the ImageData in pixels. | ||
ImageData:getPixel | Gets the color of a pixel. | ||
ImageData:getString | Gets the full ImageData as a string. | 0.9.0 | |
ImageData:getWidth | Gets the width of the ImageData in pixels. | ||
ImageData:mapPixel | Transform an image by applying a function to every pixel. | ||
ImageData:paste | Paste into ImageData from another source ImageData. | ||
ImageData:setPixel | Sets the color of a pixel. | ||
Object:release | Immediately destroys the object's Lua reference. | 11.0 | |
Object:type | Gets the type of the object as a string. | ||
Object:typeOf | Checks whether an object is of a certain type. |
Enums
ImageEncodeFormat | Image file formats supported by ImageData:encode. |
Supertypes
Examples
Load map from image
(Note that this example creates a lot of tables.)
local filename = "image.png"
local imageData = love.image.newImageData(filename)
local width, height = imageData:getDimensions()
local map = {}
for y = 1, height do
map[y] = {}
for x = 1, width do
local r, g, b, a = imageData:getPixel(x-1, y-1)
map[y][x] = {r, g, b, a}
end
end
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