1

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?

techno
  • 6,100
  • 16
  • 86
  • 192

1 Answers1

0
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?

Frank Rupprecht
  • 9,191
  • 31
  • 56