I am using ALAsset to retrieve images like that:

[[asset defaultRepresentation] fullResolutionImage]]

This return CGImageRef which I want to save to disk as fast as possible...

Solution 1:

UIImage*currentImage =[UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
NSData*currentImageData =UIImagePNGRepresentation(currentImage);
[currentImageData writeToFile:filePath atomically:YES];

Solution 2:

CFURLRef url =(__bridge CFURLRef)[NSURL fileURLWithPath:filePath];
CGImageDestinationRef destination =CGImageDestinationCreateWithURL(url, kUTTypePNG,1, NULL);
CGImageDestinationAddImage(destination,[[asset defaultRepresentation] fullResolutionImage],nil);
CGImageDestinationFinalize(destination);

The problem is that both methods are very slow performing on a device. I takes about 2 seconds per image to perform this. And this is absolutely to long.

Question: How can I speed up this image saving process? Or perhaps is there a better solution for this?

UPDATE: The best performance improvements in both solutions is to save images to JPEG format instead of PNG. So for solution 1 have replaced UIImagePNGRepresentation with UIImageJPEGRepresentation. For solution 2 have replaced kUTTypePNG with kUTTypeJPEG.

Also worth noting that second solution is way more memory efficient that first one.

SSave ALAsset image to disk fast on iOS的更多相关文章

  1. Awesome Swift

    Awesome Swift https://github.com/matteocrippa/awesome-swift A collaborative list of awesome Swift re ...

  2. fio2.1.10--HOWTO

    1.0 Overview and history    ------------------------ fio was originally written to save me the hassl ...

  3. Swift 的 pod 第三方库

    #HTTPpod 'Alamofire' #Elegant HTTP Networking in Swiftpod 'SwiftHTTP' #Thin wrapper around NSURLSess ...

  4. (转自)视频流中的DTS/PTS到底是什么;

     翻译了一下: Q:hi,这可能是一个弱智问题,但是当我使用bbMEG1.24beta17编码时,一直以来总是遇到这个下溢的问题.我从日志文件中得到的唯一启示就是我应该更改mux率...但是帮助文档却 ...

  5. 获取Linux系统运行情况信息

    代码: #include <stdio.h> #include <unistd.h> /* usleep() */ #include <stdlib.h> #inc ...

  6. iOS之9.3真机适配-Could not find Developer Disk Image问题

    Could not find Developer Disk Image 这是由于真机系统过高或者过低,Xcode中没有匹配的配置包文件,我们可以通过这个路径进入配置包的存放目录: /Applicati ...

  7. iOS 9.3真机适配-Could not find Developer Disk Image问题

    Could not find Developer Disk Image 这是由于真机系统过高或者过低,Xcode中没有匹配的配置包文件,我们可以通过这个路径进入配置包的存放目录: /Applicati ...

  8. [iOS]坑爹的ALAsset(Assets Library Framework)

    Assets Library Framework 可以用来做iOS上的多选器,选照片视频啥的啦就不介绍了. 目前的项目有点类似dropbox,可以选择设备内的照片然后帮你上传文件,使用了Assets ...

  9. [issue] [iOS 10] 升级后无法真机测试 Could not find Developer Disk Image

    说明:更新了手机的到了iOS 10.0.2.真机调试时候提示"Could not find Developer Disk Image" 并且之前就下载了Xcode8,但是没有安装X ...

随机推荐

  1. 2.4 hive创建表实例讲解

    一.create table ## 员工表 create table IF NOT EXISTS default.emp( empno int, ename string, job string, m ...

  2. 【Data Structure & Algorithm】在排序数组中查找和为定值的两个数

    在排序数组中查找和为定值的两个数 题目:输入一个已经按升序排序过的数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字,要求时间复杂度是O(n).如果有多对数字的和等于输入的数字,输出 ...

  3. Spring Boot 学习系列(08)—自定义servlet、filter及listener

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 传统的filter及listener配置 在传统的Java web项目中,servlet.filter和li ...

  4. 为Docker容器设置静态IP

    此文已由作者袁欢授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 创建docker容器 docker run -it --name=yh -h yh --net=none de ...

  5. UGUI技术之LayoutGroup布局实现详解

    继续学习unity4.6,unity的LayoutGroup分为三种, Horizontal Layout Group(水平布局)Vertical Layout Group(垂直布局)Grid Lay ...

  6. Inside Geometry Instancing(上)

    Inside Geometry Instancing(上) http://blog.csdn.net/soilwork/article/details/598335 翻译:claymanclayman ...

  7. javascript 数组、json连接

    json(或数组).concat(需要添加的json(或数组))

  8. 记录一下在SpringBoot中实现简单的登录认证

    代码参考博客: https://blog.csdn.net/weixin_37891479/article/details/79527641 在做学校的课设的时候,发现了安全的问题,就不怀好意的用户有 ...

  9. jupyter notebook dead kernel问题解决

    背景: 我在刚安装好的tensorflow环境下启动jupyter notebook,无论是浏览器还是控制台,提示都是关于dead kernel.然后就查嘛,更新大发好. 但是我在控制台里按照其他人说 ...

  10. zoj3765Lights(splay)

    链接 splay的增删改操作. 刚开始对于某段区间首先有了lazy标记时,把其左右孩子给交换了,导致在pushup时又交换了一次而debug了n久. #include <iostream> ...