CGImageRef 和绘图层

发布于 2024-08-08 22:13:01 字数 480 浏览 3 评论 0原文

我有这样的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-08-15 22:13:01

您将需要使用 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:.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文