大佬教程收集整理的这篇文章主要介绍了使用Swift(iOS)和Photos框架保存自定义图像的元数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都能指出我在正确的方向吗?
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 : @R_197_10495@ng = NS@R_197_10495@ng(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 @R_197_10495@ng; let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersion@R_197_10495@ng"]; output.adjustmentData = PHAdjustmentData(formatIdentifier: NSBundle.mainBundle().bundlEIDentifier!,formatVersion: nsObject as! @R_197_10495@ng,data: options.dataUsingEncoding(NSUTF8@R_197_10495@ngEncoding)!); changerequest.contentEdiTingOutput = output; },completionHandler: { (_bool,_error) -> Void in if !_bool && error != nil { NSLog("%@",error!); } }); }); }); },_error) -> Void in });
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框架保存自定义图像的元数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。