RGB color Binary

Source: Internet
Author: User

Principle: RGB Color According to the calculation of ' grayscale ' formula, can be converted to black and white 2 colors, achieve two value.

Business Scenario Application: Depending on the background color, take a black or white color, as the background color of the copy font color

Specific code:

    function GetTextColor (backgroundcolor) {        var threshold = 128;//Threshold        var r = parseint (Backgroundcolor.substring ( 0,2) * 0.3;        var g = parseint (backgroundcolor.substring (2,4), +) * 0.59;        var B = parseint (Backgroundcolor.substring (4,6), +) * 0.11;        var RGB = r + G + b;//first grayscale the image        if (RGB > Threshold)//And then by a threshold value of binary        {            return "000000";        } else        {            return "FFFFFF";        }    }

  

RGB color Binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.