【问题标题】:Low-res image when using PHImageManager with fixed width and variable height使用具有固定宽度和可变高度的 PHImageManager 时的低分辨率图像
【发布时间】:2015-05-12 16:20:13
【问题描述】:

我正在使用Photos Framework 请求图像按照用户定义的参数显示在 UIImageView 中。

我基本上是在使用这个代码:

var options = PHImageRequestOptions()
options.version = PHImageRequestOptionsVersion.Current
options.deliveryMode =  PHImageRequestOptionsDeliveryMode.HighQualityFormat
options.resizeMode = PHImageRequestOptionsResizeMode.Exact
options.networkAccessAllowed = true

PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: targetSize, contentMode: PHImageContentMode.AspectFill, options: options) { (result: UIImage!, info) -> Void in
    if !info[PHImageResultIsDegradedKey]!.boolValue {
        println("targetSize: \(targetSize)")
        println("asset.pixelWidth: \(asset.pixelWidth)")
        println("asset.pixelHeight: \(asset.pixelHeight)")
        println("result.size: \(result.size)")
    }
}

用户可以选择“适合宽度”或“适合高度”选项。在“适合宽度”中,我使用:

targetSize = CGSizeMake(width, PHImageManagerMaximumSize.height)

在“fit-height”中,我使用:

targetSize = CGSizeMake(PHImageManagerMaximumSize.width, height)

其中widthheight 是从UIImageView 的尺寸动态获取的。我的想法是,通过在非固定尺寸中使用 PHImageManagerMaximumSize 并在 contentMode 中使用 PHImageContentMode.AspectFill,我将获得适合我的 UIImageView 的最大图像。

“适合宽度”选项:

targetSize: (2122.40673828125, -1.0)
asset.pixelWidth: 2048
asset.pixelHeight: 1536
result.size: (60.0, 45.0)

“适合高度”选项:

targetSize: (-1.0, 2241.7099609375)
asset.pixelWidth: 2048
asset.pixelHeight: 1536
result.size: (2048.0, 1536.0)

问题发生在第一种情况下:用户在使用“fit-width”选项时看到的是分辨率非常低的图像。

是我做错了什么还是 PHImageManager 有问题?

【问题讨论】:

  • 你能举例说明你在 fit-width 和 fit-height 情况下分别为 width 和 height 传递了什么值吗?
  • Fit-width: (1000.0, -1.0) [符合(width, PHImageManagerMaximumSize.height)];适合高度:(-1.0, 1000.0) [符合(PHImageManagerMaximumSize.width, height)]。

标签: ios swift photosframework


【解决方案1】:

尝试同步调用此方法。这将立即为您提供正确尺寸和质量的图像。试试这个:

options.synchronous = true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2016-07-10
    • 2018-05-06
    相关资源
    最近更新 更多