【发布时间】:2014-12-19 01:03:42
【问题描述】:
我正在使用 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)
}
现在我需要自动拍摄所选区域的照片并保存。 有谁知道该怎么做? 谢谢!
【问题讨论】:
-
使用 CGImageCreateWithImageInRect 将其裁剪到您想要的确切部分
-
感谢您的提问!现在我知道如何在 Swift 中裁剪 CIImage。谷歌拒绝提供帮助,苹果网站也拒绝提供帮助。当您可以轻松调用 imageByCroppingToRect 方法时,我尝试使用过滤器:)
标签: image-processing swift ios8 crop core-image