Write UIImage along with metadata (EXIF, GPS, TIFF) in iPhone's Photo library

后端 未结 8 1791
情歌与酒
情歌与酒 2020-11-29 05:12

I am developing a project, where the requirements are: - User will open the camera through the application - Upon capturing an Image, some data will be appended to the captu

8条回答
  •  攒了一身酷
    2020-11-29 05:25

    There are many frameworks that deals with image and metadata.

    Assets Framework is deprecated, and replaced by Photos Library framework. If you implemented AVCapturePhotoCaptureDelegate to capture photos, you can do so:

    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
        var metadata = photo.metadata
        metadata[kCGImagePropertyGPSDictionary as String] = gpsMetadata
        photoData = photo.fileDataRepresentation(withReplacementMetadata: metadata,
          replacementEmbeddedThumbnailPhotoFormat: photo.embeddedThumbnailPhotoFormat,
          replacementEmbeddedThumbnailPixelBuffer: nil,
          replacementDepthData: photo.depthData)
        ...
    }
    

    The metadata is a dictionary of dictionaries, and you have to refer to CGImageProperties.

    I wrote about this topic here.

提交回复
热议问题