
如果可能的话,我正在寻找一种更有效的方法将此编辑过的照片保存到磁盘而不会影响质量.
我理解UIImagePNGRepresentation可能会提高质量,但这比JPEG表示更慢.
这是我目前正在做的,在默认优先级线程(qos_class_utility)上:
func jpegRepresentationOfImage(image: CIImage) -> NSData { let eaglContext = EAGLContext(API: .OpenGLES2) let ciContext = CIContext(EAGLContext: eaglContext) let outputimageRef = ciContext.createCGImage(image,fromrect: image.extent()) let uiImage = UIImage(CGImage: outputimageRef,scale: 1.0,orIEntation: UIImageOrIEntation.Up) return UIImageJPEGRepresentation(uiImage,0.9) //this takes upwards of 20-30 seconds with large photos!}//writing out to disk:var error: NSError?let success = jpegData.writetoURL(contentEditingOutput.renderedContentURL,options: NSDataWritingOptions.AtomicWrite,error: &error)解决方法 我建议使用CGImageDestination将CGImage直接传递给ImageIO.您可以将字典传递给CGImageDestinationAddImage以指示压缩质量,图像方向等. CFDataRef save_cgimage_to_jpeg (CGImageRef image){ CFMutableDataRef cfdata = CFDataCreateMutable(nil,0); CGImageDestinationRef dest = CGImageDestinationCreateWithData(data,CFSTR("public.jpeg"),1,NulL); CGImageDestinationAddImage(dest,image,NulL); if(!CGImageDestinationFinalize(dest)) ; // error CFRelease(dest); return cfdata} 总结 以上是内存溢出为你收集整理的ios – 给定CIImage,将图像数据写入磁盘的最快方法是什么?全部内容,希望文章能够帮你解决ios – 给定CIImage,将图像数据写入磁盘的最快方法是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)