菜鸟教程小白 发表于 2022-12-11 18:37:10

ios - iOS 11 中的 CGImageDestinationAddImage 错误


                                            <p><p>在应用程序中,以下代码在 iOS 版本 9.3.5 - 10.3.x 中运行良好,可将 UIImage 转换为 tiff:</p>

<pre><code>func convertUIImageToTIFF(uiImage: UIImage) -&gt; NSData {

    let propertiesTiff: = [
      kCGImagePropertyTIFFXResolution: 200 as AnyObject,
      kCGImagePropertyTIFFYResolution: 200 as AnyObject,
      kCGImagePropertyTIFFCompression: 4 as AnyObject
    ]

    let properties: = [
      kCGImagePropertyDepth: 1 as AnyObject,
      kCGImagePropertyTIFFDictionary: propertiesTiff as AnyObject
    ]

    let mutableData: CFMutableData = NSMutableData()

    if let imageDestination = CGImageDestinationCreateWithData(mutableData, kUTTypeTIFF, 1, nil), let cgImage = uiImage.cgImage {
      CGImageDestinationAddImage(imageDestination, cgImage, properties as CFDictionary?)
      CGImageDestinationFinalize(imageDestination)
    }

    return NSData(data: mutableData as Data)
}
</code></pre>

<p>这导致了一个明显被压缩的 NSData 对象,可以从它的字节数看出(根据图像内容,它在 50kb 和 220kb 之间)。</p>

<p>由于 iOS 11 Beta(在 Beta 9 上测试)添加 TIFF 属性和应用压缩不再起作用:开始发送的 tiff 文件大约为 8Mb,并且不包含 XResolutionheader (在发送到的数据中)使用 Alamofire 的服务器)。</p>

<p>感谢任何帮助。</p>

<p>更新:问题在 Beta 10 和 GM 上仍然存在。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遇到了类似的问题,并向 Apple 报告了一个错误,并提供了指向该主题的链接。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - iOS 11 中的 CGImageDestinationAddImage 错误,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46039310/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46039310/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - iOS 11 中的 CGImageDestinationAddImage 错误