cmyk Color From Rgb Color - Android Graphics

Android examples for Graphics:Color RGB Value

Description

cmyk Color From Rgb Color

Demo Code


//package com.java2s;

public class Main {
    public static float[] cmykFromRgb(int rgbColor) {
        int red = (16711680 & rgbColor) >> 16;
        int green = ('\uff00' & rgbColor) >> 8;
        int blue = 255 & rgbColor;
        float black = Math.min(1.0F - (float) red / 255.0F, Math
                .min(1.0F - (float) green / 255.0F,
                        1.0F - (float) blue / 255.0F));
        float cyan = 1.0F;
        float magenta = 1.0F;
        float yellow = 1.0F;
        if (black != 1.0F) {
            cyan = (1.0F - (float) red / 255.0F - black) / (1.0F - black);
            magenta = (1.0F - (float) green / 255.0F - black)
                    / (1.0F - black);/*  w w w .j  a  v  a2  s .c  om*/
            yellow = (1.0F - (float) blue / 255.0F - black)
                    / (1.0F - black);
        }

        return new float[] { cyan, magenta, yellow, black };
    }
}

Related Tutorials