The site cairo in the description of this function says:

The color components are floating point numbers in the range 0 to 1.

( https://www.cairographics.org/manual/cairo-cairo-t.html#cairo-set-source-rgb )

How to understand this? For example, how can I set the color in RGB (113, 208, 113) in this very "range 0 to 1"?

  • one
    It did not work with this, but the logic suggests something like this float_rgb_component = int_rgb_component / 255 - Flowneee
  • @Flowneee Thanks, works. - Vel

1 answer 1

The simplest solution is to apply this formula:

 float_rgb_component = int_rgb_component / 255.0 

PS Transferred from comments to make it easier to find the answer.

  • Actually - by 255.0, otherwise the integer division will be performed and you will get zeros ... - Harry
  • @Harry corrected - Flowneee
  • And I'm in a double castile. - Vel