简体   繁体   中英

Is there any way to convert RGB values (0-255) to CMYK value (0-99) in android studio?

I'm making an app to control the LED color of 5050 LED strip. The color picker provides me with RGB code, but the 5050 LED strip follows CMYK color format. Is there any way to convert RGB values (0-255) to CMYK value (0-99) in android studio?

Here is a simple class that will convert RGB to CMYK, normal cmyk is from 0.0 to 1.0, just use a scaler to get from 0 to 99. There is no android color converter that I have found native to convert to cmyk.

public class CMYK
    {
        float cyan = 0.0f;
        float magenta = 0.0f;
        float yellow = 0.0f;
        float black = 0.0f;


        public void convertRGBtoCMYK(int r, int g, int b)
        {

            float _r = (float) (r / 255);
            float _g = (float) (g / 255);
            float _b = (float) (b / 255);

            black = 1.0f - max(_r, _g, _b);

            cyan = (1.0f - _r - black) / (1.0f - black);
            magenta = (1.0f - _g - black) / (1.0f - black);
            yellow = (1.0f - _b - black) / (1.0f - black);
        }

        private float max(float a, float b, float c)
        {
            if (a > b && a > c)
                return a;
            if (b > a && b > c)
                return b;
            if (c > a && c > b)
                return c;

            // all equal just return a
            return a;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM