我正在尝试使用ImageIO将图像保存为HEIC文件格式。代码大致如下:
这适用于A10设备,但在旧设备和模拟器上失败(根据Apple的说法),因为无法初始化
有基于AVFoundation的API可以检查是否可以使用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设备,但在旧设备和模拟器上失败(根据Apple的说法),因为无法初始化
destination
和错误消息findWriterForType:140: unsupported file format 'public.heic'
。我找不到任何直接的方法来测试硬件是否支持HEIC,而不需要初始化新的图像目标并测试其可空性。有基于AVFoundation的API可以检查是否可以使用HEIC保存照片,例如使用
-[AVCapturePhotoOutput supportedPhotoCodecTypesForFileType:]
,但我不想仅仅为此初始化和配置捕获会话。是否有更直接的方法来查看硬件是否支持这种编码类型?