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 ...
随机推荐
- Uploadify API在项目上的应用
在项目开发中,前端使用easyui,jq的时候,我么涉及到导入的时候都要用到这个上传插件,用法是: 1:先初始化上传控件 2:打开导入的easyui dialog弹出框,dialog里面将上传的inp ...
- Flutter实战视频-移动电商-29.列表页_商品列表数据模型建立
29.列表页_商品列表数据模型建立 简历数据模型 json生成dart类的网站: https://javiercbk.github.io/json_to_dart/ json数据 {",&q ...
- 用Go语言异常机制模拟TryCatch异常捕捉
有的同学看到Go和TryCatch一起出现,心里可能会说,难道Go语言升级了,加入了try...catch语句.哈哈,其实Go语言从创建之初就没打算加入try...catch语句,因为创建Go的那帮大 ...
- 201621123016 《Java程序设计》第八周学习总结
1. 本周学习总结 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 ArrayList在调用contains方法时会调用indexOf方法得到 ...
- 使用js在html文档的任意位置输出内容
<script type="text/javascript">document.write('这里是内容');</script>
- 洛谷P4570 [BJWC2011]元素(线性基)
传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 考虑贪心 将所有的矿石按价值从大到小排序 如果一块矿石不会和之前的编号异或为0就加入 这个只要判一下它能不能加进线性基里就可以了 据说这个贪心的证明 ...
- 跳转到另一个APP
看看这个代码: http://code4app.com/codesample/4fcc512d6803fae60b000002 inApp跳转,不过需要Nimbus类库. 要跳转到另一个APP,需要另 ...
- LeetCode.897-递增搜索树(Increasing Order Search Tree)
这是悦乐书的第346次更新,第370篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第211题(顺位题号是897).给定一棵树,按中序遍历顺序重新排列树,以便树中最左边的节 ...
- 初识DetNet:确定性网络的前世今生
在刚刚落幕的2019中国 SDN/NFV/AI大会上,确定性网络(Deterministic Networking)成为了大家讨论的热点话题之一.随着工业物联网(IIoT)的兴起和工业4.0的提出,T ...
- sql 语句 替换字段的一些内容
update t_table set field = replace(field,'替换内容','替换为');