CGImageRef 和绘图层
我有这样的代码:
CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]);
CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
稍后我以这种方式在 UIImage 中加载 CGImageRef:
UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage];
我想在该图像上画一个圆圈。关键是圆圈移动了,所以必须删除并重新绘制。我想实现这一点的最佳方法是使用图层,所以我的问题是:如何向该代码添加一个图层并在其上画一个圆圈?我稍后如何重置图层并重新绘制该圆圈?
谢谢你!
I have this code:
CGDataProviderRef provider = CGDataProviderCreateWithFilename([myFile UTF8String]);
CGImageRef img = CGImageCreateWithJPEGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
Later I load that CGImageRef in a UIImage this way:
UIImage *uiImage = [[UIImage alloc] initWithCGImage:destImage];
I'd like to draw a circle over that Image. The point is the circle moves so it has to be deleted and redraw. I guess the best way of accomplishing this is with layers so my question is: How can I add a layer to that code and draw a circle on it? How can I later reset the layer and redraw that circle?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用 UIImageView,然后向该视图添加单独的图层。如果你的图层[圆]移动了,只需将其位置属性设置为新的中心即可;视图系统将负责重新组合所有内容。
要让您的圆圈显示在图层中,您可以使用固定图像、子类 CALayer 并重写drawInContext:,或者设置委托并实现drawLayer:inContext:。
You'll want to use a UIImageView, and then add a separate layer to that view. If your layer [circle] moves, just set its position property to the new center; the view system will take care of re-compositing everything.
To get your circle to show up in the layer, you can either use a fixed image, subclass CALayer and override drawInContext:, or set the delegate and implement drawLayer:inContext:.