Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if let firstImageData = UIImageJPEGRepresentation(pickedImage, 0.1) {
- self.imgArray.append(firstImageData)
- }
- extension UIImage {
- func resizeWithPercent(percentage: CGFloat) -> UIImage? {
- let imageView = UIImageView(frame: CGRect(origin: .zero, size: CGSize(width: size.width * percentage, height: size.height * percentage)))
- imageView.contentMode = .ScaleAspectFit
- imageView.image = self
- UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale)
- guard let context = UIGraphicsGetCurrentContext() else { return nil }
- imageView.layer.renderInContext(context)
- guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
- UIGraphicsEndImageContext()
- return result
- }
- func resizeWithWidth(width: CGFloat) -> UIImage? {
- let imageView = UIImageView(frame: CGRect(origin: .zero, size: CGSize(width: width, height: CGFloat(ceil(width/size.width * size.height)))))
- imageView.contentMode = .ScaleAspectFit
- imageView.image = self
- UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, scale)
- guard let context = UIGraphicsGetCurrentContext() else { return nil }
- imageView.layer.renderInContext(context)
- guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
- UIGraphicsEndImageContext()
- return result
- }
- }
- myImage = myImage.resizeWithWidth(700)!
- let compressData = UIImageJPEGRepresentation(myImage, 0.5) //max value is 1.0 and minimum is 0.0
- let compressedImage = UIImage(data: compressData!)
Add Comment
Please, Sign In to add comment