Двойная проверка, если мне нужно вызвать CGContextSaveGState и CGContextRestoreGState даже при создании нового imageContext.Нужно ли мне звонить CGContextSaveGState и CGContextRestoreGState?
Из того, что я прочитал в «Руководстве по программированию кварца», мне не нужно будет в приведенном ниже примере, потому что я создаю совершенно новый контекст изображения.
Я искал github для UIGraphicsBeginImageContextWithOptions, а некоторые люди сохраняют и восстанавливают контекст, а другие люди этого не делают.
// Uses a circularMask on an image
class func circularImage(image: UIImage, diameter: Int) -> UIImage {
assert(diameter > 0, "Diameter > 0 Failed \(__FUNCTION__)")
let frame = CGRect(x: 0.0, y: 0.0, width: Double(diameter), height: Double(diameter))
var newImage: UIImage?
UIGraphicsBeginImageContextWithOptions(frame.size, false, UIScreen.mainScreen().scale)
var context: CGContextRef = UIGraphicsGetCurrentContext()
CGContextSaveGState(context)
let imagePath: UIBezierPath = UIBezierPath(ovalInRect: frame)
imagePath.addClip()
image.drawInRect(frame)
newImage = UIGraphicsGetImageFromCurrentImageContext()
CGContextRestoreGState(context);
UIGraphicsEndImageContext()
return newImage!
}
Спасибо за ответ. – Tobias