rgb values to 0 to 1 scale

前端 未结 4 380
春和景丽
春和景丽 2021-02-02 06:53

I\'m trying to calculate some RGB colors (0 - 255) for a 0 to 1 scale. Does anyone knows a online converter or it exists a ma

相关标签:
4条回答
  • 2021-02-02 07:29

    The simplest way if to divide by either 255 for 0-1 or 256 for 0 - a bit less than 1. The latter sometimes has advantages. You need to do the divisions in fixed or floating point, not in integer arithmetic, of course.

    However in fact the human response to an rgb channel value on 0-255 is not linear, neither is the device's response. Often you need to do gamma correction. It all gets very involved very quickly, and it doesn't usually matter much for low end graphics. For high end graphics, however, you often want to be out of rgb colourspace altogether, and then you need non-linear conversion functions to finally flush the rgb pixels to the end image.

    0 讨论(0)
  • a = x / 255
    

    or

    x = a * 255
    

    where x is the RGB value and a is your desired result.

    0 讨论(0)
  • 2021-02-02 07:37

    if you want to continue using 0-255 can create a function for this as the following example.

    function setFillColor2(...)
       local object,r,b,g=...
       object:setFillColor( r/255, b/255,g/255)
    end
    
    circle1 = display.newCircle(150,250, 50 ) 
    setFillColor2(circle1,23,255,12)
    
    0 讨论(0)
  • 2021-02-02 07:45

    It's simply a case of dividing your RGB value, call it x by 255:

    If x = 95 then your value is 95/255 = 0.373 (to 3 d.p.)

    0 讨论(0)
提交回复
热议问题