如何使用 UIGraphicsBeginImageContext() 进行绘制

发布于 2024-12-25 22:44:36 字数 179 浏览 5 评论 0原文

我正在尝试生成图像,并在 Apple 文档中找到了 UIGraphicsBeginImageContext() ,它看起来很完美。我一直在看一些 Quartz 教程,在每个教程中,他们都使用自定义视图来进行绘图,这在本例中似乎没有必要,但我还不够确定。使用 UIGraphicsBeginImageContext() 进行绘图的最佳方法是什么?

Im trying to generate an image, and have found UIGraphicsBeginImageContext() in the Apple docs which looks perfect. Ive been looking at some Quartz tutorials and in each one they use a custom view to do their drawing which doesn't seem necessary in this case, but i dont know enough to be sure. Whats the best way to do my drawing using UIGraphicsBeginImageContext()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

倾听心声的旋律 2025-01-01 22:44:36

好吧,您可能想使用 UIGraphicsBeginImageContextWithOptions()scale=0.0 来获得分辨率独立性,但是,是的,一旦您调用该函数,框架就会设置正常的图形您可以像教程中一样使用上下文。您可以使用 UIGraphicsGetCurrentContext() 来获取它。

完成绘图后,您可能需要使用 UIGraphicsGetImageFromCurrentImageContext() 来实际捕获您所绘制的内容。

并且不要忘记在完成后调用 UIGraphicsEndImageContext()

Well, you probably want to use UIGraphicsBeginImageContextWithOptions() and scale=0.0 to get resolution independence, but yes, once you call the function the frameworks will have set up a normal graphics context you can use as in the tutorials. You can get at it with UIGraphicsGetCurrentContext().

When you have finished drawing you will likely want to use UIGraphicsGetImageFromCurrentImageContext()to actually capture what you have drawn.

And don't forget to call UIGraphicsEndImageContext() when finished.

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