我正在尝试使用ImageIO以HEIC文件格式保存图像。该代码看起来是这样的:验证我的设备是否能够以HEIC格式编码图像的正式方法是什么?
NSMutableData *imageData = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData(
(__bridge CFMutableDataRef)imageData,
(__bridge CFStringRef)AVFileTypeHEIC, 1, NULL);
if (!destination) {
NSLog(@"Image destination is nil");
return;
}
// image is a CGImageRef to compress.
CGImageDestinationAddImage(destination, image, NULL);
BOOL success = CGImageDestinationFinalize(destination);
if (!success) {
NSLog(@"Failed writing the image");
return;
}
这工作与A10的设备,但无法对旧设备,并在模拟器上(也可根据苹果),由于未能初始化destination
和错误消息findWriterForType:140: unsupported file format 'public.heic'
。我找不到任何直接测试硬件是否支持HEIC而无需初始化新映像目标和测试可空性的方法。
有基于AVFoundation的API用于检查照片是否可以使用HEIC保存,例如使用-[AVCapturePhotoOutput supportedPhotoCodecTypesForFileType:]
,但我不想为此初始化和配置捕获会话。
是否有更直接的方法来查看硬件是否支持这种编码类型?