rubyimage-processinglibgosu

Map image and get pixel color


I have 2 images, with same dimension and same picture, a shape. In the first image (that I show on screen), the shape is monocromatic, in the second image, shape is mapped with different color.

When I move the mouse, on the image, I want to show different text based on the color mapped on second (hidden) image.

I don't want to map square area, but irregular areas, this is my problem.

For example, when mouse cursor is on head (right image), I get color red on the left image (cached but not visualized) and I put a specific text.

Example Image

How can I load second image an get pixel color? Gosu doesn't permit to get image info (only width and height).

Any ideas?


Solution

  • At the end I choose this GEM chunky_png, because it has no dependency from other gems or library and it's perfect to my needs:

    @map_image = ChunkyPNG::Image.from_file('map_shape.png')                  
    
    # Test pixel color
    if @map_image[mouse_x - @main_image_x, mouse_y - @main_image_y] == ChunkyPNG::Color.rgb(255, 0,0)
     # Do something
    end