For a programming project, I need to read pixels from a loaded image using pyglet.
I used “pyglet.image.load(‘map.png’)” to load the image, and I found out that you can retrieve the image data using img.get_image_data().
I use line mapImage.get_region(x,y,1,1).get_image_data().get_data("RGBA", 4)
to read the data from the pixel located at (x,y). This is where I get stuck. When I print the result of the line above, I get an empty space. Could anyone clarify how I extract the RGB values from the string returned by the get_data() function?
Thanks!
Your mapImage… returns a string with 4 characters representing rgba.
Try this: