我在阅读GCD
教程https://www.raywenderlich.com/79149/grand-central-dispatch-tutorial-swift-part-1。CIFeature现在没有会员已经发布了EyeEositionPosition
当我下载开工项目,建设,我得到了一些错误:
private extension PhotoDetailViewController {
func faceOverlayImageFromImage(image: UIImage) -> UIImage {
let detector = CIDetector(ofType: CIDetectorTypeFace,
context: nil,
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
// Get features from the image
let newImage = CIImage(CGImage: image.CGImage!)
let features = detector.featuresInImage(newImage)
UIGraphicsBeginImageContext(image.size)
let imageRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
// Draws this in the upper left coordinate system
image.drawInRect(imageRect, blendMode: CGBlendMode.Normal, alpha: 1.0)
let context = UIGraphicsGetCurrentContext()
for faceFeature in features {
let faceRect = faceFeature.bounds
CGContextSaveGState(context)
// CI and CG work in different coordinate systems, we should translate to
// the correct one so we don't get mixed up when calculating the face position.
CGContextTranslateCTM(context, 0.0, imageRect.size.height)
CGContextScaleCTM(context, 1.0, -1.0)
if faceFeature.hasLeftEyePosition {
let leftEyePosition = faceFeature.leftEyePosition
let eyeWidth = faceRect.size.width/FaceBoundsToEyeScaleFactor
let eyeHeight = faceRect.size.height/FaceBoundsToEyeScaleFactor
let eyeRect = CGRect(x: leftEyePosition.x - eyeWidth/2.0,
y: leftEyePosition.y - eyeHeight/2.0,
width: eyeWidth,
height: eyeHeight)
drawEyeBallForFrame(eyeRect)
}
if faceFeature.hasRightEyePosition {
let leftEyePosition = faceFeature.rightEyePosition
let eyeWidth = faceRect.size.width/FaceBoundsToEyeScaleFactor
let eyeHeight = faceRect.size.height/FaceBoundsToEyeScaleFactor
let eyeRect = CGRect(x: leftEyePosition.x - eyeWidth/2.0,
y: leftEyePosition.y - eyeHeight/2.0,
width: eyeWidth,
height: eyeHeight)
drawEyeBallForFrame(eyeRect)
}
CGContextRestoreGState(context);
}
let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return overlayImage
}
在这一行faceFeature.hasLeftEyePosition
,它说:
Value of type 'CIFeature' has no member 'hasLeftEyePosition'
那么如何解决这个问题。
任何帮助,将不胜感激。谢谢。
只有['CIFaceFeature'(HTTPS: //developer.apple.com/library/ios/documentation/CoreImage/Reference/CIFaceFeature/index.html#//apple_ref/occ/cl/CIFaceFeature)拥有这样的属性。你需要施放它。 – HAS