2017-07-27 177 views

回答

0

这是一个简单的类,将RGB转换为CMYK,正常的cmyk是从0.0到1.0,只需使用一个缩放器即可获得0到99.没有找到本机转换为cmyk的android颜色转换器。

public class CMYK 
    { 
     float cyan = 0.0f; 
     float magenta = 0.0f; 
     float yellow = 0.0f; 
     float black = 0.0f; 


     public void convertRGBtoCMYK(int r, int g, int b) 
     { 

      float _r = (float) (r/255); 
      float _g = (float) (g/255); 
      float _b = (float) (b/255); 

      black = 1.0f - max(_r, _g, _b); 

      cyan = (1.0f - _r - black)/(1.0f - black); 
      magenta = (1.0f - _g - black)/(1.0f - black); 
      yellow = (1.0f - _b - black)/(1.0f - black); 
     } 

     private float max(float a, float b, float c) 
     { 
      if (a > b && a > c) 
       return a; 
      if (b > a && b > c) 
       return b; 
      if (c > a && c > b) 
       return c; 

      // all equal just return a 
      return a; 
     } 
    } 
相关问题