Android 顏色對比,Android顏色

來源:互聯網
上載者:User

Android 顏色對比,Android顏色

1、Android 顏色對比

    /** Calculates the constrast between two colors, using the algorithm provided by the WCAG v2. */    public static float computeContrastBetweenColors(int bg, int fg) {        float bgR = Color.red(bg) / 255f;        float bgG = Color.green(bg) / 255f;        float bgB = Color.blue(bg) / 255f;        bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f);        bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f);        bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f);        float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB;                float fgR = Color.red(fg) / 255f;        float fgG = Color.green(fg) / 255f;        float fgB = Color.blue(fg) / 255f;        fgR = (fgR < 0.03928f) ? fgR / 12.92f : (float) Math.pow((fgR + 0.055f) / 1.055f, 2.4f);        fgG = (fgG < 0.03928f) ? fgG / 12.92f : (float) Math.pow((fgG + 0.055f) / 1.055f, 2.4f);        fgB = (fgB < 0.03928f) ? fgB / 12.92f : (float) Math.pow((fgB + 0.055f) / 1.055f, 2.4f);        float fgL = 0.2126f * fgR + 0.7152f * fgG + 0.0722f * fgB;        return Math.abs((fgL + 0.05f) / (bgL + 0.05f));    }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.