PHAssetManager 在请求图像时忽略 targetSize?

PHAssetManager ignoring targetSize when requesting image?

我有一个 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

Per Apple:

To serve your request more quickly, Photos may provide an image that is slightly larger than the target size—either because such an image is already cached or because it can be generated more efficiently.

既然你想要一个特定的尺寸,那么设置上面的选项来强制请求尊重你的尺寸。

Option

case exact

Photos resizes the image to match the target size exactly.