【发布时间】:2017-02-21 09:10:17
【问题描述】:
我正在尝试使用这样的“for-loop”从 20 到 30 个 UIImage 压缩和获取 NSdata:
for theImage in selectedUIImages {
let data = UIImageJPEGRepresentation(image,0.5)
// doing something with the data
}
在 iPhone 7 上尝试过,除了我的应用程序在循环时使用高达 700MB 内存之外没有任何问题,但在旧款 iPhone 上我收到以下消息:
*Message from debugger: Terminated due to memory issue.*
主要目标是从 UIImage 中获取 NSData,以便我可以将图像放在目录中进行上传。让我解释一下:
Amazon S3 Transfer 实用程序需要图像的路径/url,因此我需要为 UIImage 创建一个路径/url,我知道的唯一方法是通过以下方式获取它:
data.write(to: URL(fileURLWithPath: localPath), options: .atomic)
【问题讨论】:
-
你在设备上试过了吗?
-
普里亚尔:你是什么意思?
-
Martin:这是 swift 3.0
-
@NSNoob 谢谢询问队友 :-) 让我解释一下。 Amazon S3 Transfer 实用程序需要图像的路径/url,因此我需要为 UIimage 创建一个路径/url,我知道的唯一方法是通过以下方式获取它:data.write(to: URL(fileURLWithPath: localPath) , 选项:.atomic)