如何在 Swift 中导出 16 位 HEIF 图像?

问题描述 投票:0回答:1

我正在尝试为我的应用程序编写一个允许 16 位深度 HEIF 文件的导出函数。 Apple 的文档没有指定是否支持 16 位,也没有指定

writeHEIFRepresentation()
方法是否需要任何特定选项。我一直在尝试使用每色 16 位(每像素 64 位)格式以及扩展 Display P3 或 HLG 色彩空间,但输出仍然是 8 位。源图像是 16 位 TIFF。

这是我的游乐场代码:

import Cocoa
import CoreImage

let originalImageURL = URL(fileURLWithPath: "/Users/myself/Desktop/DSC00990-HDR-3.tif")
let exportedImageURL = URL(fileURLWithPath: "/Users/myself/Desktop/DSC00990-HDR.heic")
guard let colorSpace = CGColorSpace(name: CGColorSpace.displayP3) else {
    print("Couldn't create a color space. :(")
    exit(1)
}
let context = CIContext()
let options = [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: 1.0 as CGFloat]

guard let image = CIImage(contentsOf: originalImageURL) else {
    print("Couldn't create an image. :(")
    exit(1)
}

do {
    _ = try context.writeHEIFRepresentation(of: image, to: exportedImageURL, format: CIFormat.RGBA16, colorSpace: colorSpace, options: options)
    print("It worked")
}
catch {
    print("It failed.")
}

请问你们有在 CoreImage 上创建 HEIF 文件的经验可以分享吗?也许Apple的编码器还不支持16位HEIF文件?

提前非常感谢您。

swift core-image bit-depth heif
1个回答
0
投票
if #available(macOS 12.0, *) {
                    try ciContext.writeHEIF10Representation(of: processImage, to: destUrl, colorSpace: colorSpace, options: options)
                }
© www.soinside.com 2019 - 2024. All rights reserved.