Question

i want to generate RGB to CMYK value using this code

    pixel = temp.getPixel(i,j);
    R = Color.red(pixel);
    G = Color.green(pixel);
    B = Color.blue(pixel);
    K = Math.min(Math.min(255-R, 255-G), 255-B);
    if (K!=255){
        c = ((255-R-K)/(255-K));
        m = ((255-G-K)/(255-K));
        y = ((255-B-K)/(255-K));
        C = (int)(255*c);
        M = (int)(255*m);
        Y = (int)(255*y);
    } else {
        C = 255-R;
        M = 255-G;
        Y = 255-B;
    }

The type of variabel pixel,R,G,B,K,C,M and Y are Integer. and the type of variabel c, m, and y are float. but when I show the result to the log cat like this,

Log.i("CMYK", String.valueOf(C)+" "+String.valueOf(M)+" "+String.valueOf(Y)+" "+String.valueOf(K));
Log.i("CMYK", String.valueOf(c)+" = ((255-"+String.valueOf(R)+"-"+String.valueOf(K)+")/(255-"+String.valueOf(K)+"))");
Log.i("CMYK", String.valueOf(m)+" = ((255-"+String.valueOf(G)+"-"+String.valueOf(K)+")/(255-"+String.valueOf(K)+"))");
Log.i("CMYK", String.valueOf(y)+" = ((255-"+String.valueOf(B)+"-"+String.valueOf(K)+")/(255-"+String.valueOf(K)+"))");

they give me this result of the log cat :

08-18 18:34:49.080: I/CMYK(819): 0 0 0 142
08-18 18:34:49.080: I/CMYK(819): 0.0 = ((255-90-142)/(255-142))
08-18 18:34:49.080: I/CMYK(819): 0.0 = ((255-113-142)/(255-142))
08-18 18:34:49.090: I/CMYK(819): 0.0 = ((255-99-142)/(255-142))

Just like the log say, value of R = 90, G = 113, and B = 99... can anyone explain me why the mathematic result are 0??

Was it helpful?

Solution

If you use Integers then:

255-90-142 = 23
255-142 = 113
23 / 113 = 0   <-- becouse it's int

Same for rest of your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top