0

Im trying to make a java script to convert from cmyk to rgb, but im having problems with re results, I found the formula online but I dont know whats wrong with my script. The problem is that the outpur is wrong, e.g. Magenta should come out as red:255 green:0 blue:255 instead of my output which is :red:255 green:252 blue:255.

public class CMYKtoRGB {
public static void main(String[] args) {
     double cyan = Double.parseDouble(args[0]);
     double magenta = Double.parseDouble(args[1]);
     double yellow = Double.parseDouble(args[2]);
     double black = Double.parseDouble(args[3]);        

     int red = (int) Math.round(255 * ( 1 - cyan/100) * (1 - black/100 ));
     int green = (int) Math.round(255 * (1 - magenta/100) * (1 - black/100));
     int blue =(int)Math.round(255*(1-yellow)*(1-black/100));       

     System.out.println(red);
     System.out.println(green);
     System.out.println(blue);
}
}```
Dindy Ba
  • 11
  • 4
  • Could you clarify what the problem is? Does it give the wrong output? Maybe you need to divide yellow by 100 like the other values? – TiiJ7 Oct 04 '22 at 13:20
  • I do not know your online source, but check Wikipedia, usually it has good explanation of initial data (which it is often a problem). In your case, you need densities (0 to 100) for CMYK, and it gives you RGB data 0-255. Note: I'm not an expert in Java, but I would add some `.` on the numbers, to force them to be floats and not integers – Giacomo Catenazzi Oct 04 '22 at 13:24
  • @TiiJ7 , ok I edited the post, I changed the formula and now I made it so that doesnt divide by 100 anymore. It works thanks – Dindy Ba Oct 04 '22 at 13:45
  • https://stackoverflow.com/a/12132630/984823 CMYK touches color profiles, so it is not simply math. By the way it might be that CMYK components are not in the range 0 - 100, but 0 - 1, so remove /100. Would explain the result. – Joop Eggen Oct 04 '22 at 13:56
  • @JoopEggen yea I removed /100 as I said in the comment before and it works now, thanks – Dindy Ba Oct 05 '22 at 15:32

0 Answers0