How would you write a simple Java program that converts RGB to CMY?...or you could give me some hints on how to write it?
Asked
Active
Viewed 1,157 times
2
-
2possible duplicate of [Convert RGB color to CMYK?](http://stackoverflow.com/questions/2426432/convert-rgb-color-to-cmyk) – taskinoor Apr 29 '11 at 12:23
-
1CMYK isn't CMY. its just an advance concept from it – Doan Dec 21 '19 at 20:05
-
1there is a similar question, maybe its usefull: https://stackoverflow.com/questions/59440192/java-converting-rgb-to-cmy-picture/59446658#59446658 – Doan Aug 26 '21 at 13:14
3 Answers
4
RGB to/from CMY
Converting from RGB to CMY is simply the following
C = 1 - R
M = 1 - G
Y = 1 - B
Please refer the below for further information

taskinoor
- 45,586
- 12
- 116
- 142

Pazhamalai G
- 154
- 1
0
Will add in
CYAN - 1 = RED
MAGENTA - 1 = GREEN
YELLOW - 1 = BLUE
from will the will
trade from rgb
RED - 1 = CYAN
GREEN - 1 = MAGENTA
BLUE - 1 = CYAN

Terry Wong
- 1
- 1
0
I am tring to convert a specifig picture as well, which is given. I kbow whow ic can calculate the CMY Value from RGB. I am reading the given picture (what is in RGB color space) pixelwise, calculate it to CMY and then whant to save it as a CMY picture.
Here is my code for Java:
import java.awt.Color;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Aufgabe2c {
public static void main(String[] args) {
try {
BufferedImage image = ImageIO.read(new File("blumen.bmp"));
iterateThroughImageToGetPixel(image);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void iterateThroughImageToGetPixel(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
System.out.println("width, height: " + width + ", " + height);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.println("x,y: " + j + ", " + i);
int pixel = image.getRGB(j, i);
getPixelARGB(pixel);
System.out.println("");
}
}
}
/*
* Quelle: https://alvinalexander.com/blog/post/java/getting-rgb-values-for-each-pixel-in-image-using-java-bufferedi
* http://openbook.rheinwerk-verlag.de/javainsel9/javainsel_20_006.htm#mj4c12381d5bacf8fb6ee31448d26890bb
*/
public static void getPixelARGB(int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
convertRGBToCMY(red, green, blue);
System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
}
public static void convertRGBToCMY(int red, int green, int blue) {
int[] cmyArray = new int[3];
//cyan
cmyArray[0] = 255 - red;
//magenta
cmyArray[1] = 255 - green;
//yellow
cmyArray[3] = 255 - blue;
Color col = new Color(new ColorSpace(), components, alpha)
// BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
// ImageIO.write(image, "bmp", new File("blumen_cym.bmp") ); // Save as BMP
// System.out.println("argb: "+ red + ", " + green + ", " + blue);
}
}