将iPhone“基于矢量的图形”放大仿射变换 [英] Scaling up iPhone "vector-based graphics" on affine transforms

查看:51
本文介绍了将iPhone“基于矢量的图形”放大仿射变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此drawRect进行了圆视图

I made a "Circle" view with this drawRect

- (void)drawRect:(CGRect)rect 
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(ctx, color.CGColor);
    CGContextAddEllipseInRect(ctx, rect);
    CGContextFillPath(ctx);
}

当我尝试使用 CGAffineTransformMakeScale放大视图时(2.0,2.0),结果模糊不清,边缘出现像素化。但是,编程指南说Quartz使用基于矢量的命令来绘制视图,并且在使用仿射变换时它们将继续看起来不错:

When I try to scale the view up using CGAffineTransformMakeScale(2.0, 2.0), the result is blurry and pixelated on the edges. However, the programming guide says that Quartz uses vector-based commands to draw views, and that they would continue to look good when using affine transforms:


Quartz绘图系统使用基于矢量的绘图模型。与基于栅格的绘图模型(其中绘图命令对单个像素进行操作)相比,使用固定比例的绘图空间(称为用户坐标空间)指定Quartz中的绘图命令。然后,iPhone OS将此绘图空间中的坐标映射到设备的实际像素上。 此模型的优势在于,使用仿射变换按比例放大或缩小时,使用矢量命令绘制的图形仍然看起来不错

还是我不使用基于矢量的命令?如果没有,我该怎么画圆呢?

Or am I not using vector-based commands? If not, how would I do that to draw a circle?

谢谢。

推荐答案

将变换应用于视图不会导致重画该视图。它所做的只是缩放视图的图层,该图层是存储在GPU上的位图纹理。

Applying a transform to a view does not cause it to be redrawn. All that it does is scale the view's layer, which is a bitmap texture stored on the GPU. This will lead to blurry graphics.

在iPhone上绘制视图时,调用 -drawRect:视图图层的内容。然后将这些内容作为纹理缓存在GPU上。

When drawing a view on the iPhone, -drawRect: is called to supply the content for the view's layer. That content is then cached as a texture on the GPU.

在本指南中,它们所指的是在-drawRect:期间应用变换的过程,正在被绘制。如果在那里使用转换(通过 CGContextConcatCTM()等),则圆会在更大比例下平滑绘制。但是,您还需要调整视图大小以反映此更大的形状。我建议在自定义视图子类上使用 scale 属性,您可以将其设置为其他比例因子,该属性将处理视图的大小调整并大幅重绘其内容。

What they are referring to in the guide is the application of a transform during -drawRect:, when the vector graphics are being drawn. If you use a transform there (through CGContextConcatCTM() or the like), the circle will be drawn smoothly at the larger scale. However, you will also need to resize your view to reflect this larger shape. I recommend using a scale property on your custom view subclass that you can set to a different scale factor and that will handle resizing the view and redrawing its contents sharply.

这篇关于将iPhone“基于矢量的图形”放大仿射变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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