0

调用此扩展程序时出现以下错误:

extension UIView {
    
    /// Create image snapshot of view.
    func snapshot(of rect: CGRect? = nil) -> UIImage {
        return UIGraphicsImageRenderer(bounds: rect ?? bounds).image { _ in
            drawHierarchy(in: bounds, afterScreenUpdates: true)
        }
    }
}

错误:

vImageConvert_AnyToAny - 失败宽度 = 0 高度 = 1 dst 组件 = 16 位浮点 dstLayout = ByteOrder16Little dstBytesPerRow = 0 src 组件 = 16 位整数 srcLayout = ByteOrder16Little srcBytesPerRow = 0

任何想法为什么会这样?想知道色彩空间问题是否......在模拟器上运行良好,在物理设备上中断。

4

1 回答 1

0

为其他需要类似解决方案的人找到了解决方案:

extension UIView {
    
    /// Create image snapshot of view.
    func snapshot(of rect: CGRect? = nil) -> UIImage {
        
        let renderer = UIGraphicsImageRenderer(bounds: rect!)
                return renderer.image { (context) in
                    self.layer.render(in: context.cgContext)
                }
    }
}
于 2022-02-14T17:15:32.597 回答