开发者

Writing java program about RGB-CMY

How would you write a simple Java program tha开发者_C百科t converts RGB to CMY?...or you could give me some hints on how to write it?


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

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


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


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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜