iOS:抗锯齿失败(CALayer中为PNG) [英] iOS: Antialiasing fail (PNG in CALayer)

查看:148
本文介绍了iOS:抗锯齿失败(CALayer中为PNG)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在屏幕上绘制此图像:

I'm attempting to draw this image on screen:

这是代码:

        CALayer* dullLayer = [CALayer layer];
        {                
            dullLayer.frame = CGRectMake(0,0,BUTTON_SIZE,BUTTON_SIZE);

            dullLayer.position = CGPointFromPoint2D( btnCenter );

            dullLayer.opacity = topQuadrant ? 1.0 : 0.5;


            [wheelLayer addSublayer: dullLayer];
        }


        UIImage* test = [UIImage imageNamed: @"OuterButton_Dull.png"];

        dullLayer.contents = (id) [test CGImage];

这就是我得到的:

有什么用?为什么边缘如此锯齿?将其与以完全相同的方式合成到屏幕上的罗马数字图像进行对比。

What gives? Why are the edges so jagged? Contrast this with the Roman numeral images that have been composited to screen in exactly the same way.

我尝试过

            dullLayer.edgeAntialiasingMask = 0x0f; // binary 1111

无济于事。

编辑: http://lists.apple.com/ archives / cocoa-dev / 2008 / Feb / msg02070.html

推荐答案

如果发布的结果图像是尺寸与屏幕上显示的尺寸相同,则您只是在使用太大的图像。 PNG图像不是矢量图像,因此按比例缩小将始终产生一些锯齿。您缩小得越远,效果越差。在这种情况下,抗锯齿效果有限。

If the result image that you posted is the same size as it appears on the screen then you are simply using too large an image. A PNG image is not a vector image, so scaling it down will always give some aliasing; the further you scale down the worse it gets. Antialiasing will have limited effect in such cases.

在数字图像中看不到它的部分原因是它不包含任何精细的高对比度,线条就像其他图像一样,部分可能是因为您正在使用较小的图像。

The fact that you don't see it for the numeral images is partly because it doesn't contain any fine, high contrast, lines like the other image does and partly perhaps because you are using smaller images for them.

如果您将原始图像作为矢量图像,请尝试将其缩小为正确的尺寸,然后再将其转换为PNG。如果您需要在应用程序的其他位置使用更高的分辨率版本,请考虑创建多个PNG,每个PNG的分辨率都不同。

If you have the original image as a vector image, try scaling that down to the right size before converting it to PNG. If you need a higher resolution version somewhere else in your app, consider creating multiple PNGs, each at different resolutions.

如果没有原始图像作为矢量图片,则应尝试查找替代图片。网上有很多免费的剪贴画文件来源,例如 http://www.openclipart.org/ http://www.clker.com/

If you don't have the original image as a vector image, you should try finding a replacement. There are a couple of good sources for free clip art files on the web, such as http://www.openclipart.org/ or http://www.clker.com/.

这篇关于iOS:抗锯齿失败(CALayer中为PNG)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆