How to fade color

后端 未结 8 1297
我寻月下人不归
我寻月下人不归 2021-02-06 05:56

I would like to fade the color of a pixel out toward white, but obviously maintain the same color. If I have a pixel (200,120,40), will adding 10 to each value to m

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 06:25

    The question, "to fade the color of a pixel out toward white" (not some shade of gray), is really about mixing the original pixel color with white, going from 100% original color and 0% white to 0% original color and 100% white. There's not more to it. Doing this in, for example, 101 steps would look like this:

    r0= 200; // as in the question
    g0= 120;
    b0=  40;
    for(i= 100; i >= 0; i--){
      r= (i * r0 + (100 - i) * 255) / 100;
      g= (i * g0 + (100 - i) * 255) / 100;
      b= (i * b0 + (100 - i) * 255) / 100;
      // use this color (r, g, b) somehow
    }
    

提交回复
热议问题