• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 启用抗锯齿时,在 drawRect 中使用不同颜色绘制重叠形状会导致边缘出血

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:55:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在绘制具有不同颜色重叠的相同形状时遇到问题。启用抗锯齿时,生成的透明像素会渗出并导致伪像,如 this image .她的顺序是画一个红色的圆圈,画一个蓝色的三角形,然后画一个红色的三角形。

这个问题可以通过禁用抗锯齿来解决,但结果是丑陋的锯齿状边缘。

是否有一些解决方案可以让我对图形上下文进行追溯抗锯齿处理或渲染到图像并在该图像上进行抗锯齿处理。或者任何其他可以帮助我绘制边缘清晰的重叠形状的东西。

这里是重现问题的代码

-(void)drawRectCGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextClearRect(currentContext, rect);
CGContextSetAllowsAntialiasing(currentContext, YES);

//// Color Declarations
UIColor* color = [UIColor redColor];
UIColor* color2= [UIColor blueColor];

//// Oval Drawing
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: rect];
[color setFill];
[ovalPath fill];

//// triangle Drawing
UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint: CGPointMake(0, 0)];
[trianglePath addLineToPoint: CGPointMake(rect.size.width, rect.size.height)];
[trianglePath addLineToPoint: CGPointMake(0, rect.size.height)];
[trianglePath addLineToPoint: CGPointMake(0, 0)];
[trianglePath closePath];
[color2 setFill];
[trianglePath fill];

[color setFill];
[trianglePath fill];
}



Best Answer-推荐答案


问题在于,使用 drawRect,您基本上是在图像上绘图,并且每个 draw 方法都会渲染前一个。没有剔除。

要真正解决这个问题,您可能希望使用 OpenGL,其中只有一个渲染 channel ,因此不会渲染隐藏的对象。

关于ios - 启用抗锯齿时,在 drawRect 中使用不同颜色绘制重叠形状会导致边缘出血,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703617/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap