Difference between revisions of "ImageData"

(Removed outdated example)
 
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
 
Raw (decoded) image data.
 
Raw (decoded) image data.
  
 
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
 
}}
 
}}
== Examples ==
+
== Enums ==
=== Images that have dimensions that are not a 2^n will display incorrectly as a white rectangle on some graphics chipsets. This function pads images so they will display correctly. ===
+
{{#ask: [[Category:Enums]] [[parent::ImageData]] [[Concept:Current]]
<source lang="lua">
+
| headers=hide
function newPaddedImage(filename)
+
| format=template
local source = love.image.newImageData(filename)
+
| template=ListingFields
local w, h = source:getWidth(), source:getHeight()
+
| introtemplate=ListingIntro
+
| outrotemplate=ListingOutro
-- Find closest power-of-two.
+
| ?Description
local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
+
| ?PrettySince
local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
+
| ?PrettyRemoved
+
}}
-- Only pad if needed:
+
== Supertypes ==
if wp ~= w or hp ~= h then
+
* [[parent::Data]]
local padded = love.image.newImageData(wp, hp)
+
* [[parent::Object]]
padded:paste(source, 0, 0)
+
return love.graphics.newImage(padded)
+
end
+
+
return love.graphics.newImage(source)
+
end
+
</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 ==
 +
{{i18n|ImageData}}

Latest revision as of 04:08, 30 March 2014

Raw (decoded) image data.

You can't draw ImageData directly to screen. See Image for that.

Constructors

Canvas:newImageData Generates ImageData from the contents of the Canvas. Added since 0.10.0
love.graphics.newScreenshot Creates a screenshot and returns the ImageData. Removed in 11.0
love.image.newImageData Creates a new ImageData object.

Functions

Data:clone Creates a new copy of the Data object. Added since 11.0
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. Added since 0.9.0
ImageData:encode Encodes ImageData.
ImageData:getDimensions Gets the width and height of the ImageData in pixels. Added since 0.9.0
ImageData:getFormat Gets the pixel format of the ImageData. Added since 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. Removed in 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. Added since 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

ImageFormat Encoded image formats.

Supertypes

See Also


Other Languages