0

我想看看为什么 UIGraphicsImageRender 没有返回图像。我们将循环 calayers 列表以将 calayer 转换为 uiimage,然后将 uiimage 存储在列表中。它发生在索引 91。我正在使用从 calayers 到图像的这个过程,然后将图像转换为视频文件。我几乎尝试了所有方法 - autoreleasepool,使用 DispatchQueue,CG_CONTEXT_SHOW_BACKTRACE 没有显示任何内容。我正在把头发拉出来。

 DispatchQueue(label: "imageQueue", qos: .utility, autoreleaseFrequency: .workItem).async {
                
                var index = 0
                while index < drawAnimationObjectsByIndex.count  {
                    if let object = drawAnimationObjectsByIndex[index] {
                        let image = self.generateImage(layer: object.parent)
                        if image.cgImage != nil {
                            //os_log("the image is generated at %d.", log: self.tag, type: .debug, index)
                            images.append(image)
                            drawAnimationObjectsByIndex[index] = nil
                            index += 1
                        }
                        else {
                            //os_log("the image is not generated at %d.", log: self.tag, type: .debug, index)
                        }
                    }
                }
                completion(images)
            }

private func generateImage(layer : CALayer) -> UIImage {
        let renderer = UIGraphicsImageRenderer(size: settings.size)
        let img = renderer.image {
            ctx in
            
            if ctx.cgContext != nil {
                layer.render(in: ctx.cgContext)
            }
            else {
                fatalError()
            }
        }
        return img
    }

它随机返回那些错误消息(不一致)-

021-05-18 09:53:56.782550-0500 apate[12603:7001594] [Unknown process name] CGBitmapContextInfoCreate: unable to allocate 74649600 bytes for bitmap data
2021-05-18 09:53:56.782663-0500 apate[12603:7001594] [Unknown process name] CGDisplayListDrawInContext: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-05-18 09:53:56.782757-0500 apate[12603:7001594] [Unknown process name] CGBitmapContextCreateImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

2021-05-18 10:19:25.856682-0500 apate[12628:7070390] [DrawingRender] the image is generated at 89.
2021-05-18 10:19:25.895884-0500 apate[12628:7070390] [DrawingRender] the image is generated at 90.
2021-05-18 10:19:25.929803-0500 apate[12628:7070390] [DrawingRender] the image is not generated at 91.
2021-05-18 10:19:25.958797-0500 apate[12628:7070390] [DrawingRender] the image is not generated at 91.
4

0 回答 0