Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert HSV(HSB) to range 0…1

I get HSB as 29, 90, 100.
How to convert it to the range 0…1?
UIColor is initialized only in this range, so I have a question.

let red: CGFloat = 1
let green: CGFloat = 0.5372
let blue: CGFloat = 0.0941


let hueOut = 29
let satOut = 90
let brightnessOut = 100


let color = UIColor(red: red, green: green, blue: blue, alpha: 1.0)

///r 1,0 g 0,537 b 0,094 a 1,0

let color2 = UIColor(hue: hueOut, saturation: satOut, brightness: brightnessOut, alpha: 1.0)

///r -9,0 g 0,0 b -3,0 a 1,0

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Looks like your hue range is 0...360 and your saturation and brightness are 0...100. You just need to convert your integer to double and divide by 360 or 100:

let color2 = UIColor(hue: Double(hueOut)/360, saturation: Double(satOut)/100, brightness: Double(brightnessOut)/100, alpha: 1.0)

This will result in r 1.0 g 0.535 b 0.1 a 1.0

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading