如何使用 UIGraphicsBeginImageContext() 进行绘制
我正在尝试生成图像,并在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您可能想使用
UIGraphicsBeginImageContextWithOptions()
和scale
=0.0 来获得分辨率独立性,但是,是的,一旦您调用该函数,框架就会设置正常的图形您可以像教程中一样使用上下文。您可以使用UIGraphicsGetCurrentContext()
来获取它。完成绘图后,您可能需要使用 UIGraphicsGetImageFromCurrentImageContext() 来实际捕获您所绘制的内容。
并且不要忘记在完成后调用
UIGraphicsEndImageContext()
。Well, you probably want to use
UIGraphicsBeginImageContextWithOptions()
andscale
=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 withUIGraphicsGetCurrentContext()
.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.