1

The problem

I'm working on an app that modifies image bits (precisely adds some data). I would like to save modified image to device photo album (camera roll) and then loaded it from there for further modifications.

I implemented functions for saving and loading image from device Photos working fine but I think that saving or loading images from Camera Roll modifies or compresses my images so my app can't decode previously done bits modifications.


What I have tried

I'm sure my app's image modification functions are working fine - I tested them on images saved and loaded with FileManager.

Functions I used for saving and loading images from Camera Roll:

Saving image:

   func saveImageToCameraRoll(image: UIImage) {
        PHPhotoLibrary.shared().performChanges({
            PHAssetChangeRequest.creationRequestForAsset(from: image)
        }, completionHandler: { success, error in
            if success {
                print("save success")
            }
            else if let error = error {
                print("save error \(error)")
            }
            else {
                print("save ok")
            }
        })
    }

Loading image is done with imagePicker:

let imagePicker = UIImagePickerController()
@IBOutlet weak var imageView: UIImageView!
@IBAction func loadImageBtnTapped(_ sender: Any) {
    imagePicker.allowsEditing = false
    imagePicker.sourceType = .photoLibrary
    present(imagePicker, animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imageView.contentMode = .scaleAspectFit
        imageView.image = pickedImage
    }
    dismiss(animated: true, completion: nil)
}

Both work fine: saved image is visible in device Photos, when loaded image appears in my app's imageView. But as I explained above, image is somehow modified so the bits representation is different than before.


Question

So the questions are:

  • is it possible to save or load uncompressed or unmodified image from device Camera Roll?

  • or is it possible to chose image compression for saving to Camera Roll (i.e. PNG or TIFF) that will not modify my image bits?

I'm currently on Swift 4, but can easily update to 4.2.

Any help will be much appreciated..

deevee
  • 1,550
  • 15
  • 21
  • 1
    Did you try loading the image using PHPhotoLibrary instead of the picker? – ThE uSeFuL Nov 02 '18 at 23:49
  • @ThEuSeFuL I tried using PHPhotoLibrary to load image instead of the picker but run into the same problem (image bits modified other way than in my app). But I didn’t find an option to chose image compression? Maybe you can guide me what and how exact function would you use for loading images? Or maybe the saving function is the problem for me here? – deevee Nov 04 '18 at 22:30

0 Answers0