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 ...
随机推荐
- Java代码加密与反编译(一):利用混淆器工具proGuard对jar包加密
Java 代码编译后生成的 .class 中包含有源代码中的所有信息(不包括注释),尤其是在其中保存有调试信息的时候.所以一个按照正常方式编译的 Java .class 文件可以非常轻易地被反编译.通 ...
- UVaLive 3905 Meteor (扫描线)
题意:给定上一个矩形照相机和 n 个流星,问你照相机最多能拍到多少个流星. 析:直接看,似乎很难解决,我们换一个思路,我们认为流星的轨迹就没有用的,我们可以记录每个流星每个流星在照相机中出现的时间段, ...
- pre 自动换行
pre { white-space:pre-wrap; word-wrap:break-word; } 增加那么一句即可!
- MySQL基础知识(一)-超详细MySQL安装教程
简介 原计划,今天这篇想要给小伙伴们讲解一下python操作mysql数据库,但是由于近期换了一台新的电脑,所以一看mysql数据库都没安装,所有才有了这篇文章.尽管网上不乏此类型的文章,但是刚好自己 ...
- [Xcode 实际操作]八、网络与多线程-(5)使用UIApplication对象发送邮件
目录:[Swift]Xcode实际操作 本文将演示如何使用应用程序单例对象,发送邮件的功能. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 注:需要使用真机进行测 ...
- jvm 调优(转)
转自 http://pengjiaheng.iteye.com/blog/538582 年轻代的设置很关键 JVM中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系 ...
- java利用myeclipse自带三大框架搭建三大框架(Hibernate+Struts2+Spring)过程详解
搭建过程因人而异,我的搭建过程大致是这样的: 1.创建一个javaweb项目: 2.导入Spring框架,上图: 2.1: 2.2: 2.3: 3.导入struts2框架,上图: 3.1: 3.2: ...
- python对数据库的操作
一 Python 操作 MySQL import pymysql pip install pymysql (1) 连接MySQL数据库 db = pymysql.connect(主机名,用户名,密 ...
- mysql 巧用存储过程
根据距离排序 CREATE DEFINER=`ln` PROCEDURE `Proc_4`(IN `lon1` double,IN `lat1` double,IN `PageStart` int,I ...
- G-华华对月月的忠诚
链接:https://ac.nowcoder.com/acm/contest/392/G 题意: 月月要参加学校的信息学集训,晚上不能陪华华聊天了.不过为了防止华华去和别的小姐姐聊天,浪费时间影响学习 ...