CMYK to RGB color matching. Write a program CMYKtoRGB that reads in four command
ID: 3742901 • Letter: C
Question
CMYK to RGB color matching. Write a program CMYKtoRGB that reads in four command line inputs C, M, Y, and K between 0 and 1, and prints the corresponding RGB parameters. Devise the appropriate formula by "inverting" the RGB to CMYK conversion formula. This is for Java. Using Dr.Java. Here is my code for RGB to CMYK and it wants me to invert the formula for CMYK to RGB.
public class Ex_1_2_32
{
public static void main(String[] args)
{
double r = Double.parseDouble(args[0]);
double g = Double.parseDouble(args[1]);
double b = Double.parseDouble(args[2]);
double w = Math.max(r / 255, Math.max(g / 255, b / 255));
double c = (w - (r / 255)) / w;
double m = (w - (g / 255)) / w;
double y = (w - (b / 255)) / w;
double k = 1 - w;
System.out.println("C = " + c);
System.out.println("M = " + m);
System.out.println("Y = " + y);
System.out.println("K = " + k);
}
}
Explanation / Answer
public class CMYKtoRGB { public static void main(String[] args) { double c = Double.parseDouble(args[0]); double m = Double.parseDouble(args[1]); double y = Double.parseDouble(args[2]); double k = Double.parseDouble(args[3]); double r = 255 * (1-c) * (1-k); double g = 255 * (1-m) * (1-k); double b = 255 * (1-y) * (1-k); System.out.println("R = " + r); System.out.println("G = " + g); System.out.println("B = " + b); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.