1

I'm trying to implement a little tool to manipulate photos on the iPhone. I'm currently using both the simulator and an iPhone 7 with iOS 13.5.1.

I've noticed that when I copy a photo from the Mac to the simulator or via iCloud to the device, the dimensions after picking it in my app differ a lot from what the macOS Photos app tells me they should be.

Example:

Panorama in macOS Photos with dimensions of 14204 × 3628 pixels is exported as original version. Finder shows the same dimensions.
Image file copied to simulator via drag & drop and opened by my app with UIImagePickerController: 2048 x 523 pixels.
Panorama copied to device via iCloud and opened by my app with UIImagePickerController: 4096 x 1046

I'd actually like to open the image with its real dimensions as shown in Finder and Photos. I'm currently using the following code:

@IBAction func btnAddProjectPressed(_ sender: Any) {
    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        imagePicker.delegate = self
        imagePicker.sourceType = .photoLibrary
        imagePicker.allowsEditing = false

        present(imagePicker, animated: true, completion: nil)
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    self.dismiss(animated: true, completion: { () -> Void in
    })
    
    pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
    imageView.image = image
 }

UPDATE:
I've managed to get the unscaled image using the .phAsset value from the info dictionary, loading the "real" image using the PHImageManager. However, this outputs the message

Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"

This problem is described in many questions here (for example this one) and I could not really find a solution. Even Apple's sample project outputs this error and doesn't show any photos or albums.

However, combining the UIImagePickerController and the PHImageManager seems to reduce this to a warning so that I do get the full-sized image.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139

0 Answers0