I use the following code to return an NSRectangle
let ciimage = ciImage.cropped(to: $0.bounds.insetBy(dx: -$0.bounds.width/1.6, dy: -$0.bounds.width/1.6) )
But the returned rectangle has unequal width and height.How can i make it a square?
I use the following code to return an NSRectangle
let ciimage = ciImage.cropped(to: $0.bounds.insetBy(dx: -$0.bounds.width/1.6, dy: -$0.bounds.width/1.6) )
But the returned rectangle has unequal width and height.How can i make it a square?
let width = $0.bounds.width; let height = $0.bounds.height
let widthInset = (width > height) ? (width - height) / 2 : 0
let heightInset = (height > width) ? (height - width) / 2 : 0
let croppedBounds = $0.bounds.insetBy(dx: widthInset, dy: heightInset)
ciImage = ciImage.cropped(to: croppedBounds)
Something like that?