Yu-Sen Han
Yu-Sen Han

Reputation: 540

iOS RGB color is Incorrect?

 UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 8.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 135.0,213.0,0.0,1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

I am draw a line use RGB(135,213,0),RGB(135,213,0) should be green. but iOS display yellow line!! why?

Upvotes: 3

Views: 4168

Answers (3)

Man of One Way
Man of One Way

Reputation: 3980

You need to have the values in the range of [0,1]. Therefore you need to divide each value by 255.

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 135.0/255.0,213.0/255.0,0.0,1.0);

Upvotes: 15

Mobile Developer
Mobile Developer

Reputation: 5760

max value is 1.0, divide each argument by 255.0

Upvotes: 3

iAmitWagh
iAmitWagh

Reputation: 453

Divide each value by 255 ie RGB(135/255,213/255,0)

Upvotes: 3

Related Questions