【问题标题】:how to draw with UIGraphicsBeginImageContext()如何使用 UIGraphicsBeginImageContext() 进行绘制
【发布时间】:2012-01-10 23:42:25
【问题描述】:

我正在尝试生成图像,并在 Apple 文档中发现 UIGraphicsBeginImageContext() 看起来很完美。我一直在看一些 Quartz 教程,在每个教程中,他们都使用自定义视图进行绘图,在这种情况下似乎没有必要,但我知道的不够多,无法确定。使用 UIGraphicsBeginImageContext() 进行绘图的最佳方法是什么?

【问题讨论】:

    标签: ios ios5 quartz-graphics quartz-2d


    【解决方案1】:

    好吧,您可能想使用UIGraphicsBeginImageContextWithOptions()scale=0.0 来获得分辨率独立性,但是是的,一旦您调用该函数,框架将设置一个普通的图形上下文,您可以在教程中使用。您可以通过UIGraphicsGetCurrentContext() 获得它。

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

    完成后不要忘记致电UIGraphicsEndImageContext()

    【讨论】:

    • 我将如何使用比例来获得分辨率独立性?
    • 查看 UIGraphicsBeginImageContextWithOptions() 的文档 - 设置 scale = 0.0 告诉 Core Graphics 选择适合设备的比例因子,使分辨率独立于当前设备。
    猜你喜欢
    • 1970-01-01
    • 2014-03-26
    • 2014-12-03
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    相关资源
    最近更新 更多