SSave ALAsset image to disk fast on iOS
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的更多相关文章
- Awesome Swift
Awesome Swift https://github.com/matteocrippa/awesome-swift A collaborative list of awesome Swift re ...
- fio2.1.10--HOWTO
1.0 Overview and history ------------------------ fio was originally written to save me the hassl ...
- Swift 的 pod 第三方库
#HTTPpod 'Alamofire' #Elegant HTTP Networking in Swiftpod 'SwiftHTTP' #Thin wrapper around NSURLSess ...
- (转自)视频流中的DTS/PTS到底是什么;
翻译了一下: Q:hi,这可能是一个弱智问题,但是当我使用bbMEG1.24beta17编码时,一直以来总是遇到这个下溢的问题.我从日志文件中得到的唯一启示就是我应该更改mux率...但是帮助文档却 ...
- 获取Linux系统运行情况信息
代码: #include <stdio.h> #include <unistd.h> /* usleep() */ #include <stdlib.h> #inc ...
- iOS之9.3真机适配-Could not find Developer Disk Image问题
Could not find Developer Disk Image 这是由于真机系统过高或者过低,Xcode中没有匹配的配置包文件,我们可以通过这个路径进入配置包的存放目录: /Applicati ...
- iOS 9.3真机适配-Could not find Developer Disk Image问题
Could not find Developer Disk Image 这是由于真机系统过高或者过低,Xcode中没有匹配的配置包文件,我们可以通过这个路径进入配置包的存放目录: /Applicati ...
- [iOS]坑爹的ALAsset(Assets Library Framework)
Assets Library Framework 可以用来做iOS上的多选器,选照片视频啥的啦就不介绍了. 目前的项目有点类似dropbox,可以选择设备内的照片然后帮你上传文件,使用了Assets ...
- [issue] [iOS 10] 升级后无法真机测试 Could not find Developer Disk Image
说明:更新了手机的到了iOS 10.0.2.真机调试时候提示"Could not find Developer Disk Image" 并且之前就下载了Xcode8,但是没有安装X ...
随机推荐
- c/c++面试12-18------关与sizeof那些事儿
12 使用sizeof计算普通变量所占空间大小 (1)不同数据类型所占字节数不同(32位 64位系统不同) int----->4 double----->8 char-------> ...
- lua基本语法
1.注释-- ; --[[ ]] 2.控制语句: if ..then .. elseif.. then.. else.. end while.. do..end repeat ..u ...
- C#实现简易ajax调用后台方法
在当前WEB当中,有些人都会抛弃asp.net的服务器控件,转而使用ajax来进行数据的交互和存储. 当我们大量使用ajax的时候,对于新手而言,肯定会创建很多的ashx或aspx页面,通过拼接参数, ...
- Junit使用注意点
注意点 1. 使用了@BeforeClass后@Ignore将会失效
- 七牛上传图片视频demo
/引入Plupload .qiniu.js后 varuploader = Qiniu.uploader({ runtimes:'html5,flash,html4',//上传模式,依次退化 brows ...
- [Xcode 实际操作]八、网络与多线程-(6)使用UIApplication对象打开地图
目录:[Swift]Xcode实际操作 本文将演示如何使用应用程序单例对象,打开地图的功能. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKi ...
- Node.js 自定义模块
Node.js内置多个模块,也可以使用第三方模块,今天学习一下如何使用自己定义的模块 在同级目录下定义两个js文件 第一个:custom1.js "use strict"; fun ...
- [題解](最短路)luogu_P2384最短路
hack: 4 4 1 2 10000 2 3 10000 3 4 10000 1 4 10000 答案:13 不能邊最短路邊取模,因為取模后最大值不一定為原來最大值,所以利用log(m*n)=log ...
- bzoj3626: [LNOI2014]LCA奇技淫巧+树剖+线段树
题目求[a,b]到c的lca深度之和 显然是一个满足区间减法的操作 于是简化为 [1,b]到c的lca深度之和 (然并卵╮(╯▽╰)╭)然后就用奇技淫巧发现 a和b的lca深度=先把根节点到a的路 ...
- Java EE学习笔记(一)
spring入门程序: 1.导入Spring的4个基础包以及commons-logging的JAR包复制到lib目录中 2.src->com.itheima.ioc包下: ①UserDao.ja ...