UIImagePNGRepresentation issues? / Images rotated by 90 degrees

前端 未结 6 788
臣服心动
臣服心动 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:58

    The following swift function resolves the problem.

    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
        }
    

    Yup it is that simple, just because the drawInRect function will take image orientation in consideration.

提交回复
热议问题