12.3 C
Wednesday, April 3, 2024

ios – Swift: Picture is not going to be saved in picture library, all the time getting error message

I would like so save a big picture (giant width) to photographs app.

I merge completely different pictures along with this technique:

func mergeImages(pictures: [[UIImage]]) -> UIImage? {
    guard let firstRowImages = pictures.first else {
        return nil // If the array is empty, there may be nothing to merge
    let sizeHeight = ((pictures.first?.first?.measurement.top ?? 0) * CGFloat(pictures.depend))
    let imageSize = firstRowImages.cut back(CGSize.zero) { (consequence, picture) -> CGSize in
        return CGSize(width: consequence.width + picture.measurement.width, top: max(consequence.top, picture.measurement.top))
    UIGraphicsBeginImageContextWithOptions(CGSize(width: imageSize.width, top: (imageSize.top * CGFloat(pictures.depend))), true, 0.0)
    var currentYOffset: CGFloat = 0.0
    for rowImages in pictures {
        var currentXOffset: CGFloat = 0.0
        for picture in rowImages {
           let imageRect = CGRect(x: currentXOffset, y: currentYOffset, width: picture.measurement.width, top: picture.measurement.top)
            picture.draw(in: imageRect)
            currentXOffset += picture.measurement.width
        currentYOffset += imageSize.top
    let mergedImage = UIGraphicsGetImageFromCurrentImageContext()
    return mergedImage

Then I wish to save this new merged picture to photographs app:

if let mergedImage = self.mergeImages(pictures: [self.rowSnapImages]) {
                        UIImageWriteToSavedPhotosAlbum(mergedImage, self, #selector(self.imageSaved(_:didFinishSavingWithError:contextInfo:)), nil)

Completion technique:

@objc func imageSaved(_ picture: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeMutableRawPointer?) {
    if let error = error {
        if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {

The scale of the merged picture ist:

Picture Dimension: (73098.0, 715.0)

I all the time get this error:

Error Area=ALAssetsLibraryErrorDomain Code=-1 "Unknown error" UserInfo={NSLocalizedDescription=Unknown error, NSUnderlyingError=0x600000e2ba20 {Error Area=PHPhotosErrorDomain Code=3303 "(null)"}}


The operation couldn’t be accomplished. (PHPhotosErrorDomain error 3303.)

I looked for any answer however nothing helped me right here. I additionally tried to avoid wasting the picture to recordsdata app, but in addition getting an error when changing the merged picture to jpeg or png.

Latest news
Related news


Please enter your comment!
Please enter your name here