I'm creating a color object using the following code.
curView.backgroundColor = [[UIColor alloc] initWithHue:229 saturation:40 brightness:75 alpha:1];
How can I retrieve RGB values from the created color object?
let swiftColor = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1) println("RGB Value is:"); println(swiftColor.
The function R*0.2126+ G*0.7152+ B*0.0722 is said to calculate the perceived brightness (or equivalent grayscale color) for a given an RGB color. Assuming we use the interval [0,1] for all RGB values, we can calculate the following: yellow = RGB(1,1,0) => brightness=0.9278.
Click on the color selector icon (the eyedropper), and then click on the color of in- terest to select it, then click on 'edit color'. 3. The RGB values for that color will appear in a dialogue box.
It really comes down to math and getting a value between 0-1. Since 255 is the maximum value, dividing by 255 expresses a 0-1 representation. Each channel (Red, Green, and Blue are each channels) is 8 bits, so they are each limited to 256, in this case 255 since 0 is included.
In iOS 5 you could use:
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha =0.0; [multipliedColor getRed:&red green:&green blue:&blue alpha:&alpha];
const CGFloat *colors = CGColorGetComponents( curView.backgroundColor.CGColor );
These links provide further details:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With