I am Trying to convert a RGB (color space) Picture to CMY (color space) picture. I can read a specific (RGB) Picture, but my problem is actually to write or save it as a CMY picture. The picture, what I want to convert is the following:
Picture
I had wrote the following code:
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
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"));
iterateThroughImage(image);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void iterateThroughImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
System.out.println("width, height: " + w + ", " + h);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
System.out.println("x,y: " + j + ", " + i);
int pixel = image.getRGB(j, i);
getPixelARGB(pixel);
System.out.println("");
}
}
}
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;
System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
}
public static void convertRGBToCMY(int red, int green, int blue) {
int cyan = 255 - red;
int magenta = 255 - green;
int yellow = 255 - blue;
System.out.println("argb: "+ red + ", " + green + ", " + blue);
}
}
I get the rgb value as a single int-value in the method iterateThroughImage(BufferedImage image)
, where I store it in the int variable pixel
. I get each Red, Green, Blue and Alpha value in the method getPixelARGB(int pixel)
.
My problem actually is that I don't know how to convert an given specific RGB picture to a CMY (color space) picture.
By the Way: the link in the answer of Pazhamalai G is not reachable, because the "under"page ist not available anymore.
I had found a quite similar question related to this question. I had postet there my question, but it was deleted (for reasons I don't know). Its the following question:
Writing java program about RGB-CMY
I Hope you can help me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…