PHAssetManager 在请求图像时忽略目标大小?



我有一个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 多像素。我该如何解决此问题?

option.resizeMode = .exact

每个苹果:

为了更快地满足您的请求,"照片"可能会提供以下图片: 略大于目标大小 - 因为此类图像 已被缓存或因为它可以更有效地生成。

由于您想要特定大小,因此设置上述选项以强制请求尊重您的大小。

选择

case exact

照片会调整图像大小以完全匹配目标大小。

相关内容

最新更新