Slide 13
Slide 13 text
let length: CGFloat = 512
let squareSize = CGSize(width: length, height: length)
UIGraphicsBeginImageContextWithOptions(squareSize, false, 1)
let ctx = UIGraphicsGetCurrentContext()!
let width = image.size.width
let height = image.size.height
let scale = min(1.0, length / min(width, height))
let transform = CGAffineTransform.identity
.concatenating(.init(translationX: -width/2, y: -height/2))
.concatenating(.init(scaleX: scale, y: scale))
.concatenating(.init(translationX: length/2, y: length/2))
ctx.concatenate(transform)
image.draw(in: CGRect(origin: .zero, size: image.size))
let resultImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
ཁٻΛͯ͢ຬͨ͢ɺUIImageΛม͢Δίʔυʢશจʣ