0

我有这个代码:

CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]);
CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);

后来我以这种方式将 CGImageRef 加载到 UIImage 中:

UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage];

我想在该图像上画一个圆圈。关键是圆圈移动,因此必须删除并重绘。我想实现这一点的最好方法是使用图层,所以我的问题是:如何在该代码中添加一个图层并在其上画一个圆圈?以后如何重置图层并重新绘制该圆圈?

谢谢!

4

1 回答 1

0

您需要使用 UIImageView,然后向该视图添加一个单独的层。如果您的图层 [circle] 移动,只需将其位置属性设置为新中心;视图系统将负责重新合成所有内容。

要让您的圆圈显示在图层中,您可以使用固定图像、子类 CALayer 并覆盖 drawInContext:,或者设置委托并实现 drawLayer:inContext:。

于 2009-10-23T14:17:56.127 回答