iOS获取UIColor对象的CMYK值

/**

* 获取UIColor对象的CMYK字符串值。

*/

- (NSString *)getCMYKStringValueByColor:(UIColor *)originColor{

// Method provided by the Colours class extension

NSDictionary *cmykDict = [self
getCMYKValueByColor:originColor];

return [NSString
stringWithFormat:@"(%0.2f, %0.2f, %0.2f, %0.2f)",

[cmykDict[@"C"]
floatValue],

[cmykDict[@"M"]
floatValue],

[cmykDict[@"Y"]
floatValue],

[cmykDict[@"K"]
floatValue]];

}

/**

*  获取UIColor对象的CMYK值。

*

*  @return

*/

- (NSDictionary *)getCMYKValueByColor:(UIColor *)originColor

{

// Convert RGB to CMY

NSDictionary *rgb = [selfgetRGBDictionaryByColor:originColor];

CGFloat C =
1 - [rgb[@"R"]floatValue];

CGFloat M =
1 - [rgb[@"G"]floatValue];

CGFloat Y =
1 - [rgb[@"B"]floatValue];

// Find K

CGFloat K =
MIN(1,MIN(C,
MIN(Y, M)));

if (K ==
1) {

C =0;

M =0;

Y =0;

}

else {

void (^newCMYK)(CGFloat *);

newCMYK = ^(CGFloat *x){

*x = (*x - K)/(1 - K);

};

newCMYK(&C);

newCMYK(&M);

newCMYK(&Y);

}

return
@{@"C":@(C),

@"M":@(M),

@"Y":@(Y),

@"K":@(K)};

}

/**

*  获取UIColor对象的RGB值。

*

*  @return 包含rgb值的字典对象。

*/

- (NSDictionary *)getRGBDictionaryByColor:(UIColor *)originColor

{

CGFloat r=0,g=0,b=0,a=0;

if ([self
respondsToSelector:@selector(getRed:green:blue:alpha:)]) {

[originColorgetRed:&r
green:&gblue:&b
alpha:&a];

}

else {

const
CGFloat *components =CGColorGetComponents(originColor.CGColor);

r = components[0];

g = components[1];

b = components[2];

a = components[3];

}

return
@{@"R":@(r),

@"G":@(g),

@"B":@(b),

@"A":@(a)};

}

时间: 2024-10-10 07:21:34

iOS获取UIColor对象的CMYK值的相关文章

iOS 获取UIColor对象的rgb值。

/** *  获取UIColor对象的rgb值. * *  @param originColor * *  @return */ - (NSString *)getHexStringByColor:(UIColor *)originColor { NSDictionary *colorDic = [self getRGBDictionaryByColor:originColor]; int r = [colorDic[@"R"] floatValue] * 255; int g = [

iOS获取UIColor对象的RGB值

- (NSDictionary *)getRGBDictionaryByColor:(UIColor *)originColor { CGFloat r=0,g=0,b=0,a=0; if ([self respondsToSelector:@selector(getRed:green:blue:alpha:)]) { [originColor getRed:&r green:&g blue:&b alpha:&a]; } else { const CGFloat *com

iOS 获取UIColor对象的HSB字符串值。

/** *  获取UIColor对象的HSB字符串值. * */ - (NSString *)getHSBStringByColor:(UIColor *)originColor { // Method provided by the Colours class extension NSDictionary *hsbDict = [self getHSBAValueByColor:originColor]; return [NSString stringWithFormat:@"(%0.2f,

iOS 获取UIColor对象的lab字符串值。

- (NSString *)getCIELABString:(UIColor *)originColor  { // Method provided by the Colours class extension NSDictionary *cieDict = [self getCIE_LabArrayByColor:originColor ]; return [NSString stringWithFormat:@"(%0.2f, %0.2f, %0.2f)", [cieDict[@&

获取JSON对象的属性值

1.问题背景 有一个json对象,其中有键值对,那怎样获取json对象中属性值 2.实现源码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

泛型获取对应对象类型属性值

1.传入一个泛型List, 2.获取泛型的类型Type type对象, 3.然后获取type 对象的对应属性PropertyInfo proInfo对象, 4.然后根据属性对象proInfo 获取泛型对象T的对应属性值 代码如下: private List<T> Test<T>(List<T> lst, string aa) { List<T> l = new List<T>(); Type t = typeof(T); string cc =

js获取json对象的key值

 <script type="text/javascript">  getJson('age'); function getJson(key){ var jsonObj={"name":"傅红雪","age":"24","profession":"刺客"}; //1.使用eval方法 var eValue=eval('jsonObj.'+key); ale

js获取json对象的属性值

// var responseData = response.data.result; for (var r in responseData) { if (responseData[r]["visible"] == 0) { responseData[r]["visible"] = "是"; } else { responseData[r]["visible"] = "否"; } } 原文地址:https:

通过反射获取某个对象下的属性值,或通过父类获取

import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; /** * 通过反射获取某个对象下的属性值,或通过父类获取 * User: wangyongfei * Date