iOS RGB颜色不正确?

时间:2011-07-25 11:44:52

标签: iphone ios ipad rgb uicolor

 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();

我画一条线使用RGB(135,213,0),RGB(135,213,0)应该是green。但iOS显示黄线!!为什么呢?

3 个答案:

答案 0 :(得分:15)

您需要具有[0,1]范围内的值。因此,您需要将每个值除以255。

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

答案 1 :(得分:3)

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

答案 2 :(得分:3)

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