이 함수는 지정한 너비 의 이미지를 반환 합니다.
func scaleImage(image: UIImage, maximumWidth: CGFloat) -> UIImage {
let rect: CGRect = CGRectMake(0, 0, image.size.width, image.size.height)
let cgImage: CGImageRef = CGImageCreateWithImageInRect(image.CGImage!, rect)!
return UIImage(CGImage: cgImage, scale: image.size.width / maximumWidth, orientation: image.imageOrientation)
}
스위프트 3.0
func scaledImage(_ image: UIImage, maximumWidth: CGFloat) -> UIImage {
let rect: CGRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
let cgImage: CGImage = image.cgImage!.cropping(to: rect)!
return UIImage(cgImage: cgImage, scale: image.size.width / maximumWidth, orientation: image.imageOrientation)
}