UIImagePNGRepresentation issues? / Images rotated by 90 degrees

前端 未结 6 789
臣服心动
臣服心动 2020-11-29 20:30

I want to load images from UIImagePickerController, then save the selected photo to my app\'s document directory.

UIImage *image = [info objectForKey:UIImage         


        
6条回答
  •  没有蜡笔的小新
    2020-11-29 20:53

    Please try this one.

    func rotateImage(image: UIImage) -> UIImage? {
            if (image.imageOrientation == UIImage.Orientation.up ) {
                return image
            }
            UIGraphicsBeginImageContext(image.size)
            image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))
            let copy = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return copy
        }
    

    Happy Codding :)

提交回复
热议问题