旋转的 CGImage/CGlayer 的抗锯齿看起来有锯齿,UIImageView 的则不是

发布于 2024-08-13 08:10:20 字数 893 浏览 6 评论 0原文

我需要使用旋转灰度图像来掩盖“纹理”图像。

我发现,我必须使用 CGImagesCGlayers 来完成此操作(如果有更简单的方法仅使用 UIImageViews,请告诉我关于它)。

我的问题很简单:

任何的抗锯齿 旋转变换的 CG 东西很安静 锯齿状...

...但是旋转变换的 UIImageView 的抗锯齿效果有点完美。我怎样才能产生美丽的抗锯齿旋转?

我上传了一份涉及实际 iPhone 模拟器屏幕截图的“证据”,看看我在说什么:http://gotoandplay.freeblog.hu/files/Proof.png

我尝试使用CGImagesCGLayersUIImageViews用renderInContext“捕获”,我尝试将CGContextSetInterpolationQuality设置为高,并且还尝试设置CGContextSetAllowsAntialiasing - CGContextSetShouldAntialias< /em>,但每种情况都返回相同的锯齿状结果。

我计划明年学习使用 OpenGL,但此开发应该仅使用 CoreGraphics 发布。请让我知道如何获得完美渲染的旋转图像,我只是无法接受这是不可能的。

I need to mask a "texture" image with a rotated greyscale image.

I found out, that I have to do it with CGImages or CGlayers (if there is a simplier way using UIImageViews only, please let me know about it).

My problem is simple:

The antialias of any
rotation-transformed CG stuff is quiet
jaggy...

... but the antialias of a rotation-transformed UIImageView is kinda perfect. How can I produce that beautiful antialiased rotations?

I've uploaded a "proof" involving actual iPhone Simulator screenshots, to see what am I talkin' about: http://gotoandplay.freeblog.hu/files/Proof.png

I've tried to use CGImages, CGLayers, UIImageViews "captured" with renderInContext, I've tried to CGContextSetInterpolationQuality to high, and also tried to set CGContextSetAllowsAntialiasing - CGContextSetShouldAntialias, but every case returned the same jaggy result.

I'm planning to learn using OpenGL next year, but this development should released using CoreGraphics only. Please let me know how to get a perfectly rendered rotated image, I just can't accept it's impossible.

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

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

发布评论

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

评论(3

凉墨 2024-08-20 08:10:20

要为图像添加 1px 透明边框,请使用此

CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext( imageRect.size ); 
[image drawInRect:CGRectMake(1,1,image.size.width-2,image.size.height-2)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

To add 1px transparent border to your image use this

CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContext( imageRect.size ); 
[image drawInRect:CGRectMake(1,1,image.size.width-2,image.size.height-2)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
咽泪装欢 2024-08-20 08:10:20

您是否尝试过在图像周围添加清晰的 1 像素边框?我听说有人建议将其作为避免锯齿的技巧,即在混合边缘时为 CoreGraphics 提供一些工作空间。

Have you tried adding a clear, 1 pixel border around your image? I've heard of that recommended as a trick to avoid aliasing, by giving CoreGraphics some room to work with when blending the edges.

拥醉 2024-08-20 08:10:20

我也遇到了类似的问题,看起来我也要把它移到 OpenGL ES 上。我无法确定一个不影响性能的有效解决方案。

作为未来 CoreGraphics 浏览器的参考,放置 1 像素透明边框确实在我的实验中带来了显着的改进,但似乎正如 Eonil 提到的那样,您最终会遇到多个阶段的抗锯齿/平滑/插值相互对抗。 IE:CGLayer 会对其旋转进行一些插值,然后绘制它的上下文将进行一些插值/抗锯齿,依此类推,直到最终看起来非常粗糙。

实际上,通过在目标上下文上禁用插值和抗锯齿,我最终获得了更好的结果,尽管它仍然明显是锯齿状的(尽管总体上伪像较少)。通过在构造 CGLayer 时启用插值和抗锯齿,并在重新绘制目标上下文时禁用它,我能够实现最佳的整体外观。显然,这种方法还存在其他问题。

I am having a similar problem, looks like I'm going to move it over to OpenGL ES as well. I can't nail down an effective solution that doesn't hurt performance.

For reference of future CoreGraphics explorers, putting a 1-pixel transparent border did make for a noticeable improvement in my experiments, but it appears that as Eonil mentioned, you end up with multiple stages of antialiasing/smoothing/interpolation working against each other. IE: CGLayer does some interpolation for it's rotation, then context it's being drawn to will do some interpolation/antialiasing, so on so forth until it ends up looking pretty rough.

I actually ended up with better results by disabling interpolation and antialiasing on the destination context, though it was still obviously jaggy (less artifacts overall though). I was able to achieve the best overall appearance by enabling interpolation and antialiasing when constructing the CGLayer, and disabling it for the destination context when re-drawing it. This approach, obviously, is fraught with other problems.

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