编写关于RGB-CMY的java程序

时间:2011-04-29 12:11:44

标签: java

你如何编写一个简单的Java程序,将RGB转换为CMY?...或者你可以给我一些关于如何编写它的提示?

3 个答案:

答案 0 :(得分:3)

RGB到/来自CMY

从RGB转换为CMY只是以下

C = 1 - R
M = 1 - G
Y = 1 - B

请参阅以下内容以获取更多信息

http://paulbourke.net/texture_colour/convert/

答案 1 :(得分:0)

将加入

   CYAN - 1 = RED
   MAGENTA - 1 = GREEN
   YELLOW - 1 = BLUE

将来自遗嘱

从rgb进行交易

RED - 1 = CYAN
GREEN - 1 = MAGENTA
BLUE - 1 = CYAN

答案 2 :(得分:0)

我也打算转换指定的图片,这已给出。我可以通过RGB计算CMY值。我正在按像素读取给定的图片(在RGB颜色空间中),将其计算为CMY,然后希望将其另存为CMY图片。

这是我的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);
    }
}