Info: Utilizzo di Swift e della funzione CGImageSourceCreateWithURL.Swift che accede al dizionario EXIF
Sto tentando di caricare un file da un URL e quindi modificare un dizionario che contiene tutti i dati di quella particolare foto.
Questo è il codice dal file .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)
Anche se proprietà immagine Stampa tutti i dati come ci si aspetterebbe, nessuno importa quello che ho attmpted estrarre dal dizionario imageProperties - è sempre restituito come null - come ad esempio 'apertura' nell'esempio. L'immagine Proprietà stampa come;
[{TIFF}: {
Artist = JOHN;
Copyright = "[email protected]";
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..
ho fatto un sacco di ricerca e sperimentazione e io semplicemente non può capire quello che sto facendo male per accedere agli elementi in questo dizionario - Qualcuno potrebbe darmi un esempio di come vorrei impostare una variabile come il Elemento "Modello" all'interno del dizionario?
Grazie per qualsiasi aiuto, John
C'è un modo per ottenere informazioni sulla fotocamera dalla libreria di foto? Grazie –
Sì, ho modificato la mia risposta per mostrare un esempio su come farlo nell'ultimo Swift/Xcode – Cortex