Given a background color, how to get a foreground color that makes it readable on that background color?

后端 未结 6 709
有刺的猬
有刺的猬 2020-12-02 13:41

Given a background color, how to get a foreground color that makes it readable on that background color?

I mean computing that foreground color automatically in a pr

6条回答
  •  时光取名叫无心
    2020-12-02 14:11

    In case this could still be useful for someone, this is the Dart implementation based on the answers above

    Color getInverseBW(Color color) {
        double luminance = (0.2126 * color.red + 0.7152 * color.green + 0.0722 * color.blue);
        return (luminance < 140) ? Color(0xffffffff) : Color(0xff000000);
    }
    

提交回复
热议问题