我正在尝试从URL加载文件,然后编辑包含该特定照片中所有数据的字典.
这是.swift文件中的代码.
let url = NSURL(string: "http://jwphotographic.co.uk/Images/1.jpg") let imageSource = CGImageSourceCreateWithURL(url,nil) let imagePropertIEs = CGImageSourcecopyPropertIEsAtIndex(imageSource,nil) as Dictionary println(imagePropertIEs) //this is an example let aperture = imagePropertIEs[kCGImagePropertyGPSLatitude] as! NSNumber! /* //these are all being defined as nil //Load the ones from the exif data of the file let lensUsed = imagePropertIEs[kCGImagePropertyExifFocalLength] let aperture = imagePropertIEs[kCGImagePropertyExifApertureValue] as! let isoSpeed = imagePropertIEs[kCGImagePropertyExifISOSpeedratings] as! NSNumber let latitude = imagePropertIEs[kCGImagePropertyGPSLatitude] as! NSNumber let longitude = imagePropertIEs[kCGImagePropertyGPSLongitude] as! NSNumber let shutterSpeed = imagePropertIEs[kCGImagePropertyExifShutterSpeedValue] as! NSNumber let cameraname = imagePropertIEs[kCGImagePropertyExifBodySerialNumber] as! NSNumber */ println(aperture)
尽管图像属性打印的所有数据都是预期的,但无论我从imagePropertIEs字典中提取的是什么,它总是返回为null – 例如示例中的’aperture’. imagePropertIEs打印为;
[{TIFF}: { Artist = JOHN; copyright = "johnrwatson0@gmail.com"; DateTime = "2015:07:31 21:07:05"; Make = Canon; Model = "Canon EOS 7D Mark II"; ResolutionUnit = 2; Software = "Adobe Photoshop lightroom 6.0 (Macintosh)"; XResolution = 72; YResolution = 72;},{IPTC}: { Byline = ( JOHN ); copyrightNotice = etc.. etc..
我已经做了很多研究和测试,我根本无法解决我在访问这本词典中的元素时所做的错误 – 有人能举例说明如何将变量设置为字典中的“Model”元素?
解决方法 在Swift 3.0中,我找到了以下解决方案let url = NSURL(string: "http://jwphotographic.co.uk/Images/1.jpg")let imageSource = CGImageSourceCreateWithURL(url,nil)let imagePropertIEs = CGImageSourcecopyPropertIEsAtIndex(imageSource,nil) as Dictionary?let exifDict = imagePropertIEs?[kCGImagePropertyExifDictionary]
现在您可以通过例如访问exif-Tags
let dateTimeOriginal = exifDict?[kCGImagePropertyExifDateTimeOriginal]Swift.print("dateTimeOriginal: \(dateTimeOriginal)")
您将获得可选值,如果有值或零,则必须进行测试.有关可用属性常量的列表,请查看apple documentation.
总结以上是内存溢出为你收集整理的ios – Swift访问EXIF字典全部内容,希望文章能够帮你解决ios – Swift访问EXIF字典所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)