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..