qchenqizhi / QCropper

Image cropping/rotating/straightening library for iOS in Swift
MIT License
268 stars 51 forks source link

Circular Cropper is not working #18

Closed waqasrasheed86 closed 1 year ago

waqasrasheed86 commented 1 year ago

Circular Cropper is not cropped the circular shape. it return only the square cropped image

qchenqizhi commented 1 year ago

I think it is a more general way to generate a square image. The circular effect can be implemented through the cornerRadius of UIImageView. Maybe you can use this code to generate a circular image from a square image:


let image = UIImage()
let cornerRadius: CGFloat = image.size.width / 2

UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale)

let rect = CGRect(origin: .zero, size: image.size)
UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius).addClip()
image.draw(in: rect)

let result = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()