Swift 3 和 CGContextDrawImage [英] Swift 3 and CGContextDrawImage

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

问题描述

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

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

根据

谁能帮我处理这个新的 swift 3 语法代码?

解决方案

你需要像调用CGContext的实例方法一样调用它:

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

查看CGContext的最新参考.

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)

According to the CoreGraphics.apinotes CGContextDrawImage was converted to CGContext.draw :

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

When I try to do :

 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):

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

解决方案

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))

Check the latest reference of CGContext.

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

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