gpt4 book ai didi

ios - 快速访问 EXIF 字典

转载 作者:搜寻专家 更新时间:2023-10-30 21:49:13 27 4
gpt4 key购买 nike

信息:使用 Swift 和 CGI​​mageSourceCreateWithURL 函数。

我正在尝试从 URL 加载文件,然后编辑包含该特定照片的所有数据的字典。

这是 .swift 文件中的代码。

    let url = NSURL(string: "http://jwphotographic.co.uk/Images/1.jpg")
let imageSource = CGImageSourceCreateWithURL(url, nil)
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, 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..

我已经做了很多研究和测试,但我根本无法弄清楚我在访问这本字典中的元素时做错了什么 - 有人能给我一个例子,我如何将变量设置为“模型”元素在字典里面?

最佳答案

在 Swift 3.0 中我找到了以下解决方案

let url = NSURL(string: "http://jwphotographic.co.uk/Images/1.jpg")
let imageSource = CGImageSourceCreateWithURL(url, nil)
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary?
let exifDict = imageProperties?[kCGImagePropertyExifDictionary]

现在您可以通过例如访问 exif 标签

let dateTimeOriginal = exifDict?[kCGImagePropertyExifDateTimeOriginal]
Swift.print("dateTimeOriginal: \(dateTimeOriginal)")

您将获得可选值,您必须测试是否有值或 nil。有关可用属性常量的列表,请查看 apple documentation .

关于ios - 快速访问 EXIF 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31888319/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com