1
JPGファイルからメタデータを書き直してみます。私はメタデータに1つのキーワードを追加したい。 Xcodeはエラーは発生しませんが、ファイルは変更されません。私は、変数「pathToOpenFile」へのファイルからのパスを書くSwift 2.2を使用して.jpgファイルにメタデータを書き換えるOS X
var pathToOpenFile:NSURL?
次へ: はここに私のコードです。 ユーザーは、アクションを働く、NSTextFieldにENTERボタンを押した場合:それは動作しない理由を
@IBAction func endEditKeys(sender: AnyObject) {
if (pathToOpenFile != nil) {
let imageSource = CGImageSourceCreateWithURL(pathToOpenFile!, nil)
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource!, 0, nil)! as NSDictionary;
let exifDict = imageProperties.valueForKey("{IPTC}") as! NSDictionary;
var Keywords:[String] = exifDict.valueForKey("Keywords") as! [String];
Keywords.append("ANY")
exifDict.setValue(Keywords, forKey: "Keywords")
let type = CGImageSourceGetType(imageSource!)
let count = CGImageSourceGetCount(imageSource!)
let mutableData = NSMutableData(contentsOfURL: pathToOpenFile!)
let destination = CGImageDestinationCreateWithData(mutableData!, type!, count, nil)
let removeExifProperties: CFDictionary = exifDict
for i in 0..<count {
CGImageDestinationAddImageFromSource(destination!, imageSource!, i, removeExifProperties)
}
CGImageDestinationFinalize(destination!)
}
}
あなたは、私を助けることができる(メタデータを変更しませんか)?ありがとうございました!