# Get Pixel info

**URL:** <https://forums.solar2d.com/t/get-pixel-info/356518>\
**Category:** Advanced Graphics\
**Created:** [May 7, 2024, 10:26am UTC](https://forums.solar2d.com/t/get-pixel-info/356518 "2024-05-07T10:26:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LourencoA](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@LourencoA](https://forums.solar2d.com/u/LourencoA)\
**Post date:** [May 7, 2024, 10:26am UTC](https://forums.solar2d.com/t/get-pixel-info/356518/1 "2024-05-07T10:26:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Il.Sui](https://forums.solar2d.com/user_avatar/forums.solar2d.com/il.sui/32/3223_2.png) [@Il.Sui](https://forums.solar2d.com/u/Il.Sui)\
**Post date:** [May 7, 2024, 3:53pm UTC](https://forums.solar2d.com/t/get-pixel-info/356518/2 "2024-05-07T15:53:07Z")

</div>

> [@LourencoA](#):
>
> 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](https://docs.coronalabs.com/plugin/memoryBitmap/type/MemoryBitmap/getPixel.html)~~

(Wrong suggestion)

---

<div class="post-metadata">

**Author:** ![LourencoA](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@LourencoA](https://forums.solar2d.com/u/LourencoA)\
**Post date:** [May 7, 2024, 4:17pm UTC](https://forums.solar2d.com/t/get-pixel-info/356518/3 "2024-05-07T16:17:57Z")

</div>

Hello, thanks for your help.

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

```auto
-- 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.

---

<div class="post-metadata">

**Author:** ![Il.Sui](https://forums.solar2d.com/user_avatar/forums.solar2d.com/il.sui/32/3223_2.png) [@Il.Sui](https://forums.solar2d.com/u/Il.Sui)\
**Post date:** [May 7, 2024, 5:42pm UTC](https://forums.solar2d.com/t/get-pixel-info/356518/4 "2024-05-07T17:42:24Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![LourencoA](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/l/779978/32.png) [@LourencoA](https://forums.solar2d.com/u/LourencoA)\
**Post date:** [May 7, 2024, 6:27pm UTC](https://forums.solar2d.com/t/get-pixel-info/356518/5 "2024-05-07T18:27:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StarCrunch](https://forums.solar2d.com/user_avatar/forums.solar2d.com/starcrunch/32/67_2.png) [@StarCrunch](https://forums.solar2d.com/u/StarCrunch)\
**Post date:** [May 7, 2024, 8:06pm UTC](https://forums.solar2d.com/t/get-pixel-info/356518/6 "2024-05-07T20:06:45Z")

</div>

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