Java tutorial
//package com.java2s; //License from project: Apache License public class Main { private static void rgb2cmyk(int R, int G, int B, int[] cmyk) { float C = 1 - (float) R / 255; float M = 1 - (float) G / 255; float Y = 1 - (float) B / 255; float K = 1; if (C < K) K = C; if (M < K) K = M; if (Y < K) K = Y; if (K == 1) { //pure black C = 0; M = 0; Y = 0; } else { C = (C - K) / (1 - K); M = (M - K) / (1 - K); Y = (Y - K) / (1 - K); } cmyk[0] = (int) Math.round(C * 100); cmyk[1] = (int) Math.round(M * 100); cmyk[2] = (int) Math.round(Y * 100); cmyk[3] = (int) Math.round(K * 100); } }