gpt4 book ai didi

ios - PHAssetManager 在请求图像时忽略 targetSize?

转载 作者:行者123 更新时间:2023-11-28 11:56:49 27 4
gpt4 key购买 nike

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

关于ios - PHAssetManager 在请求图像时忽略 targetSize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50805761/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com