将 RGB 值传递给 CGContextSetRGBStrokeColor 无法正常工作

发布于 2025-01-03 02:21:34 字数 1246 浏览 1 评论 0原文

对于橙色,我传递 rgb 值 255-140-0

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);对我来说它画的是黄色!不是橙色的。

我尝试测试 CGContextSetRGBStokeColor 的一些低于 255 的随机值,它向我绘制白色。我不知道为什么会这样!

@ALL 任何人都可以在这个问题上给我建议吗

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{


    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:drawImage];
    currentPoint.y -= 20;
    UIGraphicsBeginImageContext(drawImage.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);

    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

for Orange i pass rgb value 255-140-0

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0); For me its drawing yellow! not orange.

I try to test some random value below 255 to the CGContextSetRGBStokeColor, it drawing white color to me. I dont know why it like that!

@ALL can any one advice me in this issue

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{


    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:drawImage];
    currentPoint.y -= 20;
    UIGraphicsBeginImageContext(drawImage.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);

    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭⌒浅淡时光〆 2025-01-10 02:21:35

查看文档,它指出为 Red Green 和 Blue 传递的值是浮点数,

The graphics context for which to set the current stroke color.
red
The red intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
green
The green intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
blue
The blue intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
alpha
A value that specifies the opacity level. Values can range from 0.0 (transparent) to 1.0 (opaque). Values outside this range are clipped to 0.0 or 1.0.

因此这些值必须在 0.0 和 1.0 之间。您输入的数字太大。以后,请先检查文档。

Looking at the documentation, it states that the values passed for Red Green and Blue are floats

The graphics context for which to set the current stroke color.
red
The red intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
green
The green intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
blue
The blue intensity value for the color to set. The DeviceRGB color space permits the specification of a value ranging from 0.0 (zero intensity) to 1.0 (full intensity).
alpha
A value that specifies the opacity level. Values can range from 0.0 (transparent) to 1.0 (opaque). Values outside this range are clipped to 0.0 or 1.0.

So the values have to be between 0.0 and 1.0. You are putting too large numbers in. In future, please check the documentation first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文