UIImage+Extension.swift 651 B

1234567891011121314151617181920212223242526
  1. //
  2. // UIImage+Extension.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/11/21.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIImage {
  10. /// EZSE: scales image
  11. public class func scaleTo(image: UIImage, w: CGFloat, h: CGFloat) -> UIImage {
  12. let newSize = CGSize(width: w, height: h)
  13. UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
  14. image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
  15. let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
  16. UIGraphicsEndImageContext()
  17. return newImage
  18. }
  19. }