Skip to content

How to save image in document directory with EXIF Data. #13

@vijayradke

Description

@vijayradke

How can I save image with Metadata in document directory and read it again from document directory?

I am saving image as below,

do {
                try imageData?.write(to: url)
                logGPSData(imageData: imageData!)

            } catch {
                print("Error", error)
       }

Reading GPS data as below, By adding location data.

func getGPSData(_ image: UIImage) {
        
        let imageData = UIImageJPEGRepresentation(image, 1.0)
        var source: CGImageSource? = nil
        source = CGImageSourceCreateWithData((imageData as CFData?)!, nil)
        let metadata = CGImageSourceCopyPropertiesAtIndex(source!, 0, nil) as? [AnyHashable: Any]
        var metadataAsMutable = metadata
        
        if let GPSDictionary = (metadataAsMutable?[(kCGImagePropertyGPSDictionary as String)]) as? [AnyHashable: Any] {
            print(GPSDictionary.debugDescription)
        }else {
            print("no GPS Data")
        }
        print(metadata?.debugDescription)
    }

Do I am missing anything? Please guide me here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions