Utilizzo CoreImage Framework per il rilevamento di biglietti da visita. Quando rilevo un rettangolo (CIDetectorTypeRectangle) ho disegnare una sovrapposizione con questo metodo:Immagine di iOS 8 Core che salva una sezione di un'immagine tramite Swift
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)
}
Ora ho bisogno di prendere automaticamente una foto dell'area selezionata e salvarlo. Qualcuno sa come farlo? Grazie!
Usa CGImageCreateWithImageInRect per ritagliare alla porzione esatto che si desidera – Sandeep
Grazie per la domanda! Ora so come ritagliare CIImage in Swift. Google ha rifiutato di aiutare così ha fatto il sito di Apple. Ho provato ad usare i filtri quando puoi facilmente chiamare il metodo imageByCroppingToRect :) – alexsalo