ImageIO
Low-level image container I/O: read EXIF / GPS / TIFF / IPTC metadata, and encode images to formats (and with embedded metadata) that UIImage.toPNGData / toJPEGData can't produce.
Why not just use
UIImage? AUIImageis a decoded bitmap — by the time you have one, the original file's metadata (EXIF, GPS, ...) is already gone, andtoPNGData/toJPEGDatacannot write HEIC / TIFF / GIF.ImageIOworks at the encoded-container level, so it can both read existing metadata and write it back.
ImageIO.readMetadata(source)
Reads container-level metadata from a file path or Data. Rejects if the source can't be decoded as an image.
The well-known dictionaries (exif / gps / tiff / iptc) use Apple's CGImageProperties key names verbatim (gps.Latitude, exif.DateTimeOriginal, ...).
ImageIO.writeImage(options)
Encodes and writes an image to to. Provide exactly one of image or source:
Tag a photo with GPS while keeping its EXIF
Use the source variant — re-encoding through a UIImage would drop the original EXIF:
Caveats
imagedrops original metadata. AUIImageis a decoded bitmap. To preserve a file's existing EXIF/GPS, use thesourcevariant, notimage.qualityonly applies to jpeg / heic. It's ignored for png / tiff / gif.- HEIC encoding requires a device/simulator that supports the HEVC image encoder; on older simulators HEIC may fail — fall back to jpeg if
writeImagerejects. - Key names are raw CGImageProperties keys. When writing
exif/gps/tiff/iptc, use Apple's key names (e.g.Latitude,LatitudeRef,DateTimeOriginal).
