核心图形 – Swift 3和CGContextDrawImage

前端之家收集整理的这篇文章主要介绍了核心图形 – 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.

原文链接:https://www.f2er.com/swift/320010.html

猜你在找的Swift相关文章