ImageData (简体中文)

Raw (decoded) image data.

You can't draw ImageData directly to screen. See Image for that. 你不能直接绘制ImageData到屏幕上,参见Image

Constructors

love.image.newImageData Creates a new ImageData object.

Functions

Data:getPointer Gets a pointer to the Data.
Data:getSize Gets the size in bytes of the Data.
ImageData:encode Encodes ImageData.
ImageData:getHeight Gets the height of the ImageData.
ImageData:getPixel Gets the pixel at the specified position.
ImageData:getString Gets the full ImageData as a string.
ImageData:getWidth Gets the width of the ImageData.
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:type Gets the type of the object as a string.
Object:typeOf Checks whether an object is of a certain type.

Examples

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.

尺寸不是2^n的图片往往无法正常显示而是变成了白块,这个函数可以解决这个问题

function newPaddedImage(filename)
    local source = love.image.newImageData(filename)
    local w, h = source:getWidth(), source:getHeight()
   
    -- 寻找最相近的两个pow.
    local wp = math.pow(2, math.ceil(math.log(w)/math.log(2)))
    local hp = math.pow(2, math.ceil(math.log(h)/math.log(2)))
   
    -- Only pad if needed:
    if wp ~= w or hp ~= h then
        local padded = love.image.newImageData(wp, hp)
        padded:paste(source, 0, 0)
        return love.graphics.newImage(padded)
    end
   
    return love.graphics.newImage(source)
end

Supertypes

Data Object

See Also


Other Languages

Personal tools