What is a formal way to check if my device is capable of encoding HEIC images?

I am trying to save an image in HEIC file format using ImageIO. The code looks something like this:

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;
}

This works on devices with A10, but does not work on older devices and on the simulator (also according to Apple), without initiating destinationan error message findWriterForType:140: unsupported file format 'public.heic'. I could not find any direct way to check if the hardware supports HEIC without initializing a new image destination and testing for nullability.

There are AVFoundation-based APIs to check if photos can be saved using HEIC, for example using -[AVCapturePhotoOutput supportedPhotoCodecTypesForFileType:], but I don’t want to initialize and set up a capture session just for that.

, ?

+4
2

ImageIO CGImageDestinationCopyTypeIdentifiers, CFArrayRef CGImageDestinationRef. , HEIC :

#import <AVFoundation/AVFoundation.h>
#import <ImageIO/ImageIO.h>

BOOL SupportsHEIC() {
  NSArray<NSString *> *types = CFBridgingRelease(
      CGImageDestinationCopyTypeIdentifiers());
  return [types containsObject:AVFileTypeHEIC];
}
+4

:

func supports(type: String) -> Bool {
    let supportedTypes = CGImageDestinationCopyTypeIdentifiers() as NSArray
    return supportedTypes.contains(type)
}

(, AVFileTypeHEIC):

if #available(iOS 11.0, *) {
    supports(type: AVFileTypeHEIC)
}
+1

Source: https://habr.com/ru/post/1684564/


All Articles