任何人都能指出我在正确的方向吗?
PHPhotolibrary.sharedPhotolibrary().performChanges({let assets : PHFetchResult = PHAsset.fetchAssetsWithLocalIDentifIErs([self.localIDentifIEr],options: nil);let asset : PHAsset = assets[0] as! PHAsset;let changeRequest = PHAssetChangeRequest(forAsset: asset);changeRequest.location = self.currentLocation;asset.requestContentEditinginputWithOptions(nil,completionHandler: { (input: PHContentEditinginput?,info: [NSObject : AnyObject]) -> VoID in guard let input = input else { return } let imageManager : PHImageManager = PHImageManager(); let requestoptions : PHImageRequestoptions = PHImageRequestoptions(); requestoptions.resizeMode = PHImageRequestoptionsResizeMode.None; imageManager.requestimageForAsset(asset,targetSize: PHImageManagerMaximumSize,contentMode: PHImageContentMode.Default,options: PHImageRequestoptions(),resultHandler: { (let image : UIImage?,_) -> VoID in let output : PHContentEditingOutput = PHContentEditingOutput(contentEditinginput: input); PHPhotolibrary.sharedPhotolibrary().performChanges({ () -> VoID in let changeRequest = PHAssetChangeRequest(forAsset: asset); /* Neu */ let imageData : NSData = NSData(contentsOfURL: (input.fullSizeImageURL)!)!; let image : CIImage = CIImage(data: imageData)!; let dataPtr = CFDataCreate(kcfAllocatorDefault,UnsafePointer<UInt8>(imageData.bytes),imageData.length) // Save off the propertIEs let imageSource : CGImageSourceRef = CGImageSourceCreateWithData(dataPtr,nil)!; var Metadata : NSMutableDictionary = NSMutableDictionary(dictionary: CGImageSourcecopyPropertIEs(imageSource,nil)!);/* Add some values to Metadata */.... NSLog("New Metadata: %@",Metadata); // Save the image let outputimageSource : CGImageSourceRef = CGImageSourceCreateWithData(dataPtr,nil)!; let jpegData : CFMutableDataRef = CFDataCreateMutable(kcfAllocatorDefault,0); let outputDestination : CGImageDestinationRef = CGImageDestinationCreateWithData(jpegData,CGImageSourceGetType(outputimageSource)!,1,nil)!; // add the image data to the destination CGImageDestinationAddImageFromSource(outputDestination,outputimageSource,Metadata); if CGImageDestinationFinalize(outputDestination) { NSLog("Successful image creation."); // process the image rendering,adjustment data creation and finalize the asset edit. } else { NSLog("Image creation Failed."); } (jpegData as NSData).writetoURL(output.renderedContentURL,atomically: true); let options : String = Nsstring(format: "%f|%f|%f|%f|%f|%f",self.saturationSlIDer.value,self.warmthSlIDer.value,self.brightnessSlIDer.value,self.sharpnessSlIDer.value,self.contrastSlIDer.value,self.gammaSlIDer.value ) as String; let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"]; output.adjustmentData = PHAdjustmentData(formatIDentifIEr: NSBundle.mainBundle().bundleIDentifIEr!,formatVersion: nsObject as! String,data: options.dataUsingEnCoding(NSUTF8StringEnCoding)!); changeRequest.contentEditingOutput = output; },completionHandler: { (_bool,_error) -> VoID in if !_bool && error != nil { NSLog("%@",error!); } }); });});},_error) -> VoID in});解决方法 您可以在creationRequest对象上添加/设置一些属性.我不知道添加自定义元数据.
PHPhotolibrary.shared().performChanges({ let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: self.anImage!) let aLocation = CLLocation(latitude: 27.63866,longitude: -80.39707) creationRequest.location = aLocation creationRequest.isFavorite = true creationRequest.creationDate = Date()},completionHandler: {success,error in if !success { print("error creating asset: \(error!)") } else { print("success creating asset!") }})总结
以上是内存溢出为你收集整理的使用Swift(iOS)和Photos框架保存自定义图像的元数据全部内容,希望文章能够帮你解决使用Swift(iOS)和Photos框架保存自定义图像的元数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)