How to get dpi/ppi of image in iOS? Maybe raw image file contains this information, so I can get ppi/dpi from NSData? Thank you.
Swift 5 solution: You can get the DPI information from the image metadata. imageData is of NSData type.
guard let imageSource = CGImageSourceCreateWithData(imageData, nil),
let metaData = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any],
let dpi = metaData["DPIWidth"] as? Int else {
return
}
print(dpi)