Why are images from the UIImagePickerController sometimes cropping incorrectly?

Sometimes images selected from photo album c UIImagePickerControllerare cropped differently than how the user wants to sow it. This happens in approx. 1 out of 50 image downloads.

When this happens, images are always cropped to part of the image from the upper left corner. Here is an example of an image with (1) showing in the red box what the user supposedly chooses to crop, and (2) which image ends on the server.

enter image description here

(1) , , , . . , , , , , .

, .

(, ):

class ImagePicker {

    private let imagePicker = UIImagePickerController()

    func showPicker() {
        imagePicker.sourceType = .PhotoLibrary
        imagePicker.mediaTypes = [kUTTypeImage as String]
        imagePicker.allowsEditing = true
        imagePicker.delegate = delegate
        imagePicker.modalPresentationStyle = .OverFullScreen
        parentViewController.presentViewController(imagePicker, animated: true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
            uploadImage(image)
        }

        picker.dismissViewControllerAnimated(true, completion: nil)
    }

    func uploadImage(image: UIImage) {

        let imageData = UIImageJPEGRepresentation(image, 0.75)!
        let imageFile = PFFile(name: "image.png", data: imageData)

        // Upload to Open Source Parse Server which stores the image in an Amazon S3 bucket.
        let imageObject = PFObject(className: "ImageClass")
        imageObject(imageFile, forKey: "imageFile")
        imageObject.saveInBackground()
    }
}

- , ?

:

iPad, , .

+4
1

. ImageView. "scaleAspectFill". , .

0

Source: https://habr.com/ru/post/1653535/


All Articles