SimpleExif icon indicating copy to clipboard operation
SimpleExif copied to clipboard

How to save image in document directory with EXIF Data.

Open vijayradke opened this issue 6 years ago • 0 comments

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.

vijayradke avatar Sep 26 '18 12:09 vijayradke