【问题标题】:Swift PHImageManager Photo Gallery Image Get PHImageManagerMaximumSize after collection view cell selectedSwift PHImageManager 照片库图像在选择集合视图单元格后获取 PHImageManagerMaximumSize
【发布时间】:2019-07-04 18:33:55
【问题描述】:

我的场景,我正在将照片库照片加载到水平集合视图单元格 Imageview 中。为了快速加载图像,我给了PHImagemanagertargetSize: CGSize(width: 120.0, height: 120.0)。现在,一旦用户在水平 CollectionView 中选择单元格,就需要获取 PHImageManagerMaximumSize 实际的高质量照片以用于预览图像。如何实现?

cell.tag = Int(manager.requestImage(for: asset,
                                            targetSize: CGSize(width: 120.0, height: 120.0),  //PHImageManagerMaximumSize
                                            contentMode: .aspectFill,
                                            options: option) { (result, _) in
                                            cell.picImage?.image = result

})

// MARK: - UICollectionViewDelegate protocol
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        let selectedCell = collectionView.cellForItem(at: indexPath) as! GalleryCollectionViewCell
        previewImage.image = selectedCell.picImage.image // here I need to get full size exact image (not cropped image)
}

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    您应该保存 2 张图片。第一个是完整的原始图像,第二个是裁剪图像。

    首先:当用户选择图像时,将原始图像保存到磁盘(使用保护纵横比裁剪图像并注意图像大小)并再次裁剪相同的图像(120x120)并保存磁盘。

    当单元格可见时从磁盘读取到内存。

    小心!如果图片太大,你的内存使用量会增加太多,操作系统会导致你的应用崩溃,所以不要在内存中保留太多图片

    您可以为可见细胞计数设置缓冲区图像。

    如果用户选择单元格,您可以显示原始图像

    【讨论】:

    • 有没有其他解决方案@Vicaren
    猜你喜欢
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2014-03-04
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多