简体   繁体   English

iOS RGB颜色不正确?

[英]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 . 我画一条线使用RGB(135,213,0),RGB(135,213,0)应该是绿色的 but iOS display yellow line!! 但iOS显示黄线!! why? 为什么?

You need to have the values in the range of [0,1]. 您需要具有[0,1]范围内的值。 Therefore you need to divide each value by 255. 因此,您需要将每个值除以255。

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

将每个值除以255即RGB(135 / 255,213 / 255,0)

最大值为1.0,将每个参数除以255.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM