ios - Is it possible to add own metadata in captured Images in Swift -
i'm new swift , ios programming. to, mentioned above, insert own metadata captured images before save them album.
i'm trying done code. saved image not contain own metadata, generated metadata. can please tell me i'm doing wrong?
or maybe isn't possible add own new metadata table captured images?
thanks lot help
@ibaction func btnpressed(sender: uibutton) { capturepicture() } func capturepicture(){ stillimageoutput.outputsettings = [avvideocodeckey: avvideocodecjpeg] session.addoutput(stillimageoutput) if let connection = self.stillimageoutput.connectionwithmediatype(avmediatypevideo) { self.stillimageoutput.capturestillimageasynchronouslyfromconnection(connection) { (imagedatasamplebuffer, error) -> void in if error == nil { var asset = alassetslibrary() let imagedata = avcapturestillimageoutput.jpegstillimagensdatarepresentation(imagedatasamplebuffer) // metadata of image var metadata:nsdictionary = cmcopydictionaryofattachments(nil, imagedatasamplebuffer, cmattachmentmode(kcmattachmentmode_shouldpropagate)).takeunretainedvalue() // metadata want add testing purpose var meta : nsdictionary = ["ersteller": "dennis","datum" : "25.04.14","ort" : "köln" ] asset.writeimagedatatosavedphotosalbum(imagedata, metadata: meta [nsobject : anyobject], completionblock: { (path:nsurl!, error:nserror!) -> void in println("\(path)") println("\(error)") }) } } } }
just convert below code swift. below code written in objective-c. need create iptc or tiff dictionary. add value suitable iptc/tiff key , write dictionary data(meta data) on image.
- (void) imagepickercontroller: (uiimagepickercontroller *)picker didfinishpickingmediawithinfo: (nsdictionary *)info { uiimage *image = info[uiimagepickercontrolleroriginalimage]; //here current system date , time , store description of photo nsdateformatter *dateformatter=[[nsdateformatter alloc] init]; [dateformatter setdateformat:@"dd-mm-yyyy"]; nslog(@"date formatter : %@",[dateformatter stringfromdate:[nsdate date]]); //hh:mm:ss nsdateformatter *timeformatter=[[nsdateformatter alloc] init]; [timeformatter setdateformat:@"hh:mm:ss"]; nslog(@"time formatterr : %@",[timeformatter stringfromdate:[nsdate date]]); //add iptc dictionary data meta data nsmutabledictionary *iptcdict = [nsmutabledictionary dictionary]; [iptcdict setvalue:[[dataengine sharedinstance] getalbumname] forkey:(nsstring *)kcgimagepropertyiptcobjecttypereference]; //folder name [iptcdict setvalue:@“renish dadhaniya - 101" forkey:(nsstring *)kcgimagepropertyiptcobjectattributereference]; //add image id -get using query database [iptcdict setvalue:[nsstring stringwithformat:@“renish sweet memory "forkey:(nsstring *)kcgimagepropertyiptcobjectname]; //add image name [iptcdict setvalue:[dateformatter stringfromdate:[nsdate date]]forkey:(nsstring *)kcgimagepropertyiptcdatecreated]; //add image date [iptcdict setvalue:[timeformatter stringfromdate:[nsdate date]]forkey:(nsstring *)kcgimagepropertyiptctimecreated]; //add image time nsmutabledictionary *dict = [nsmutabledictionary dictionary]; [dict setvalue:iptcdict forkey:(nsstring *)kcgimagepropertyiptcdictionary]; //get iamge url __block nsurl *imageassesturl = nil; [assetlib writeimagetosavedphotosalbum:image.cgimage metadata:dict completionblock:^(nsurl* asseturl, nserror* error) { if (error) { nslog(@"image not safed assets library: %@", error); imageassesturl = nil; } else { nslog( @"image safed asseturl: %@", asseturl); imageassesturl = asseturl; } }]; [picker dismissviewcontrolleranimated:yes completion:nil]; }
Comments
Post a Comment