Get Pixel info

Hello,
Is there a way to iterate through an image texture and get general info about the pixel (r, g, b and alpha) ?

Hi,
I think you are looking for this:
https://docs.coronalabs.com/plugin/memoryBitmap/type/MemoryBitmap/getPixel.html

(Wrong suggestion)

Hello, thanks for your help.

I used the code in the example, but it create an empty image that works fine.

-- Create image using the bitmap texture
local bitmap = display.newImageRect( tex.filename, tex.baseDir, 100, 100 )
bitmap.x = display.contentCenterX
bitmap.y = display.contentCenterY
 
-- Set a pixel color in the bitmap
tex:setPixel( 10, 10, 1, 0, 0, 1 )  -- Set pixel at (10,10) to be red
-- tex:setPixel( 10, 10, {1,0,0,1} )  -- Same using table syntax for RGB+A color
 

But how to init the bitmap with a custom image file?
I tried :

local bitmap = display.newImageRect( “image.png”, 100, 100 )

But the setPixel or getPixel does not work.

Oh sorry, the plugin you need is Bytemap, not memoryBitmap.

Here’s an example to ger RGB values from every pixel of a given image:

local Bytemap = require("plugin.Bytemap")
local bm = Bytemap.loadTexture{filename = "yourFile.png", is_non_external = true}
local w, h = bm.width, bm.height
local data = bm:GetBytes{format = "rgb"}
for i=1,h do
    for j=1,w do
        print("line " .. i, "column " .. j, data:byte((i-1)*w*3+(j-1)*3+1), data:byte((i-1)*w*3+(j-1)*3+2), data:byte((i-1)*w*3+(j-1)*3+3))
    end
end
1 Like

Great ! exactly what I was looking for.
Any documents related to the plugin. I couldn’t find them.

Here they are: https://ggcrunchy.github.io/corona-plugin-docs/DOCS/Bytemap/api.html

1 Like