2016-09-15 229 views
14

我想這條線轉換爲雨燕3當前語法的代碼,但似乎也存在一些問題:斯威夫特3和CGContextDrawImage

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

按照CoreGraphics.apinotesCGContextDrawImage轉化爲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) 

似乎還有一些簡單的語法,擾亂編譯器,但我看不到(其實我收到一個典型的模棱兩可的錯誤):

enter image description here

誰能幫我這個新雨燕3語法的代碼?

回答

32

你需要調用它,彷彿它是CGContext一個實例方法:

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

檢查the latest reference of CGContext

+0

謝謝你,它完美的作品。 'self'這個例子的初始屬性讓我分心:) –

+0

可愛的感謝隊友 –