Swift 3和CGContextDrawImage [英] Swift 3 and CGContextDrawImage

查看:234
本文介绍了Swift 3和CGContextDrawImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将此行转换为Swift 3当前语法代码,但似乎存在一些问题:

I want to translate this line to the Swift 3 current syntax code but seems there are some problems:

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, width: image!.size.width, height: image!.size.height), byTiling: false) 

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

Seems there is some simple syntax that disturb the compiler but I cannot see (in fact I receive a typical ambiguous error):

有人可以用这个新的swift 3语法代码帮助我吗?

Can anyone help me with this new swift 3 syntax code?

推荐答案

您需要调用它,就像它是CGContext的实例方法一样:

You need to call it as if it's an instance method of CGContext:

context.draw(image!.cgImage!, in: CGRect(x: 0.0,y: 0.0,width: image!.size.width,height: image!.size.height))

检查 CGContext 的最新参考.

Check the latest reference of CGContext.

这篇关于Swift 3和CGContextDrawImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆