核心图形 – Swift 3和CGContextDrawImage

我想将此行转换为Swift 3当前语法代码,但似乎存在一些问题:
CGContextDrawImage(context,CGRect(x:0.0,y: 0.0,width: image!.size.width,height: image!.size.height),image!.cgImage)

根据CoreGraphics.apinotes CGContextDrawImage转换为CGContext.draw:

Name: CGContextDrawImage
  # replaced by draw(_ image: CGImage,in rect: CGRect,byTiling: Bool = false)
  SwiftName: CGContext.__draw(self:in:image:)
  SwiftPrivate: true

当我尝试做:

CGContext.draw(context as! CGImage,in: CGRect(x:0.0,y:0.0,byTiling: false)

似乎有一些简单的语法干扰编译器,但我看不到(实际上我收到一个典型的模糊错误):

任何人都可以帮助我使用这个新的swift 3语法代码吗?

您需要将其称为CGContext的实例方法:
context.draw(image!.cgImage!,in: CGRect(x: 0.0,height: image!.size.height))

检查the latest reference of CGContext.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...