Example 19: RGB to CMYK Color Conversion
Learn how to convert RGB color to CMYK color.
We'll cover the following
Problem
In the digital world, colours are specified in Red-Green-Blue (RGB) format, with R, G, and B values varying on an integer scale from 0 to 255. On the other hand, in print publishing, the colours are mentioned in Cyan-Magenta-Yellow-Black (CMYK) format, with C, M, Y, and K values varying on a real scale from 0.0 to 1.0.
Write a program that converts RGB color to CMYK color as per the following formulae:
- Invalid RGB Values
- CMYK = cyan, magenta, yellow, black
❗Note: If the RGB values are all 0, then the CMY values are all 0, and the K value is 1.
Get hands-on with 1400+ tech skills courses.