我正在使用CoreImage框架来检测名片。当我检测到一个矩形(CIDetectorTypeRectangle)时,我会使用以下方法绘制覆盖层:
func drawOverlay(image: CIImage, topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint) -> CIImage {
var overlay = CIImage(color: CIColor(red: 0, green: 0, blue: 1.0, alpha: 0.3))
overlay = overlay.imageByCroppingToRect(image.extent())
overlay = overlay.imageByApplyingFilter("CIPerspectiveTransformWithExtent",
withInputParameters: [
"inputExtent": CIVector(CGRect: image.extent()),
"inputTopLeft": CIVector(CGPoint: topLeft),
"inputTopRight": CIVector(CGPoint: topRight),
"inputBottomLeft": CIVector(CGPoint: bottomLeft),
"inputBottomRight": CIVector(CGPoint: bottomRight)
])
return overlay.imageByCompositingOverImage(image)
}
现在我需要自动拍摄选定区域的照片并保存。有人知道如何做吗?谢谢!