Difference between revisions of "(Image):replacePixels"

(Created page with "{{newin|0.11.0|110|type=function|text=This function replaces (Image):refresh}} Replace the contents of an Image. == Function == === Synopsis === <source lang="lua">...")
 
(Clarify that `slice` and `reloadmipmaps` are optional)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{newin|[[0.11.0]]|110|type=function|text=This function replaces [[(Image):refresh]]}}
+
{{newin|[[11.0]]|110|type=function|text=This function replaces [[(Image):refresh|Image:refresh]]}}
  
 
Replace the contents of an Image.
 
Replace the contents of an Image.
Line 6: Line 6:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Image:replacePixels( data, slice, mipmap )
+
Image:replacePixels( data, slice, mipmap, x, y, reloadmipmaps )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
 
{{param|ImageData|data|The new [[ImageData]] to replace the contents with.}}
 
{{param|ImageData|data|The new [[ImageData]] to replace the contents with.}}
{{param|number|slice|Which slice to replace, if applicable.}}
+
{{param|number|slice (nil)|Which [[TextureType|cubemap face, array index, or volume layer]] to replace, if applicable; the value is ignored otherwise.}}
{{param|number|mipmap (0)|The mimap level of the new ImageData. If 0 Image:replacePixels will generate new mimaps.}}
+
{{param|number|mipmap (1)|The mimap level to replace, if the Image has mipmaps.}}
 +
{{param|number|x (0)|The x-offset in pixels from the top-left of the image to replace. The given ImageData's width plus this value must not be greater than the pixel width of the Image's specified mipmap level.}}
 +
{{param|number|y (0)|The y-offset in pixels from the top-left of the image to replace. The given ImageData's height plus this value must not be greater than the pixel height of the Image's specified mipmap level.}}
 +
{{param|boolean|reloadmipmaps (true/false)|Whether to generate new mipmaps after replacing the Image's pixels. True by default if the Image was created with automatically generated mipmaps, false by default otherwise.}}
 +
 
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.

Latest revision as of 11:56, 29 April 2024

Available since LÖVE 11.0
This function replaces Image:refresh.


Replace the contents of an Image.

Function

Synopsis

Image:replacePixels( data, slice, mipmap, x, y, reloadmipmaps )

Arguments

ImageData data
The new ImageData to replace the contents with.
number slice (nil)
Which cubemap face, array index, or volume layer to replace, if applicable; the value is ignored otherwise.
number mipmap (1)
The mimap level to replace, if the Image has mipmaps.
number x (0)
The x-offset in pixels from the top-left of the image to replace. The given ImageData's width plus this value must not be greater than the pixel width of the Image's specified mipmap level.
number y (0)
The y-offset in pixels from the top-left of the image to replace. The given ImageData's height plus this value must not be greater than the pixel height of the Image's specified mipmap level.
boolean reloadmipmaps (true/false)
Whether to generate new mipmaps after replacing the Image's pixels. True by default if the Image was created with automatically generated mipmaps, false by default otherwise.

Returns

Nothing.

Examples

function love.load()
    imagedata = love.image.newImageData("pig.png")
    image = love.graphics.newImage(imagedata)
end

function love.draw()
    love.graphics.draw(image)
end

function love.keypressed(key)
    if key == "e" then
        -- Modify the original ImageData and apply the changes to the Image.
        imagedata:mapPixel(function(x, y, r, g, b, a) return r/2, g/2, b/2, a/2 end)
        image:replacePixels(imagedata)
    end
end

See Also

Other Languages