Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get RGB values from UIColor?

Tags:

ios

rgb

uicolor

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?

like image 1000
defmech Avatar asked Jan 12 '09 21:01

defmech


People also ask

How do I get RGB values from UIColor Swift?

let swiftColor = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1) println("RGB Value is:"); println(swiftColor.

How do you calculate RGB value?

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.

How do I find the RGB value of a monitor?

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.

Why do RGB values range from 0 to 255?

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.


2 Answers

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]; 
like image 118
Teetotum Avatar answered Oct 04 '22 00:10

Teetotum


const CGFloat *colors = CGColorGetComponents( curView.backgroundColor.CGColor ); 

These links provide further details:

  • UIColor Reference
  • CGColorGetComponents reference
like image 32
codelogic Avatar answered Oct 03 '22 23:10

codelogic