【发布时间】:2018-11-21 04:16:29
【问题描述】:
我有一个PHAssets 列表,我需要从中获取一定大小的图像。
为了测试这一点,我将尺寸设置为设备屏幕的尺寸
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
option.isSynchronous = true
for asset in assets {
manager.requestImage(for: asset, targetSize: CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in
//prints the proper bounds for a screen
print("width and height \(UIScreen.main.bounds.width) \(UIScreen.main.bounds.height)")
//prints 2304.0 3072.0 for width and height respectively
print("result size \(result!.size.width) \(result!.size.height)\n")
self.photos.append(result!)
})
}
我需要将生成的照片切割成我指定的尺寸,但它们相差超过 2000 像素。我该如何解决这个问题?
【问题讨论】:
-
我目前无法访问文档,但我似乎记得当您同步获取图像时,每个图像可能会获得多个结果。回调中的信息可以告诉你给定的结果是否是最终结果。
-
@matt 它的意思正是它听起来的样子。实际图像的大小比请求的大小大 2000 多像素 看看代码中每个打印语句上方的 cmets。打印的值就在那里
-
@rmaddy 不,不适用于
isSynchronous=true -
@matt,它在后台线程中......
-
@matt 对。当它是异步的时候就是我所说的。
标签: ios swift image photos phasset