PHPhotoLibrary error while saving image at url

后端 未结 2 1599
野的像风
野的像风 2021-01-13 04:51

I create an image at url provided by PHContentEditingOutput. When I load data to UIImage and save it like this - it works.

[[PHPhot         


        
相关标签:
2条回答
  • 2021-01-13 05:44

    When passing the metadata, I also had the issue consistently showing whenever the Orientation (inside the image metadata) was anything other than CGImagePropertyOrientationUp.

    This is also stated inside the renderedContentURL documentation:

    Edited asset content must incorporate (or “bake in”) the intended orientation of the asset. That is, the orientation metadata (if any) that you write in the output image or video file must declare the “up” orientation, and the image or video data must appear right-side up when presented without orientation metadata.

    For images, the following metadata keys need to be updated (while the image data is also rotated):
    kCGImagePropertyTIFFDictionary \ kCGImagePropertyTIFFOrientation
    kCGImagePropertyOrientation
    • possibly, kCGImagePropertyIPTCImageOrientation

    0 讨论(0)
  • 2021-01-13 05:46

    The problem is in the file format. I was trying to edit PNG screenshot, but renderingContentURL was always tmp/filename.JPG. At first I thought it was a bug, but according to the documentation this is correct behaviour.

    renderedContentURL

    Read this property to find a URL for writing edited asset content. Then, if editing a photo asset, write the altered photo image to a file in JPEG format at this URL. If editing a video asset, export the video to a QuickTime (.mov) file at this URL.

    The solution is to convert the image with function

    NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);
    
    0 讨论(0)
提交回复
热议问题