iphone - 在仿射变换上放大 iPhone "vector-based graphics"

标签 iphone vector core-graphics quartz-graphics

我用这个drawRect制作了一个“圆形” View

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

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

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

The Quartz drawing system uses a vector-based drawing model. Compared to a raster-based drawing model, in which drawing commands operate on individual pixels, drawing commands in Quartz are specified using a fixed-scale drawing space, known as the user coordinate space. iPhone OS then maps the coordinates in this drawing space onto the actual pixels of the device. The advantage of this model is that graphics drawn using vector commands continue to look good when scaled up or down using an affine transform.

或者我没有使用基于向量的命令?如果没有,我该如何画一个圆?

谢谢。

最佳答案

对 View 应用变换不会导致 View 被重绘。它所做的只是缩放 View 层,即存储在 GPU 上的位图纹理。这将导致图形模糊。

在 iPhone 上绘制 View 时,-drawRect:被调用来为 View 层提供内容。然后,该内容将作为纹理缓存在 GPU 上。

他们在指南中提到的是在绘制矢量图形时在 -drawRect: 期间应用变换。如果您在那里使用变换(通过 CGContextConcatCTM() 等),则将以更大的比例平滑地绘制圆。但是,您还需要调整 View 大小以反射(reflect)这个较大的形状。我建议使用 scale自定义 View 子类上的属性,您可以将其设置为不同的比例因子,并将处理调整 View 大小并急剧重绘其内容。

关于iphone - 在仿射变换上放大 iPhone "vector-based graphics",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2168419/

相关文章:

iphone - 检测 UIWebView 中的 Zoomscale

iphone - 无法在 Interface Builder 中更改 UITableViewCell 大小

c++ - 访问存储在 vector 中的对象:使用 std::vector::at 或 std::vector::operator[]?

matlab - 使用 MATLAB 在 x 上对函数 f(x) 进行数值积分,其中 f(x) 具有另一个参数 y,它是一个向量

iphone - 如何屏蔽 UIImage 以使白色在 iphone 上变得透明?

ios - 将 BGRA 转换为 ARGB

macos - 永久修改 RGB Gamma 表

ios - 为什么在 Animation 中使用 self.view.layoutIfNeeded() 会导致 App 卡顿?

iphone - 动画添加/删除 UISearchBar 到/从 UITableView tableViewHeader

c++ - 使用 C++ vector 作为缓冲区