Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
745 views
in Technique[技术] by (71.8m points)

core graphics - Swift 3 and CGContextDrawImage

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...