Applying metadata to image causes performChanges request to fail

前端 未结 5 633
感动是毒
感动是毒 2021-02-06 15:29

I am using PhotoKit to edit photos and I need to preserve the metadata from the original photo. To do so I save the metadata then provide it to the options paramete

5条回答
  •  情深已故
    2021-02-06 15:57

    Certain keys in the metadata seem to cause failure. This works:

    NSArray *validMetadataKeys = @[
        (NSString *)kCGImagePropertyTIFFDictionary,
        (NSString *)kCGImagePropertyGIFDictionary,
        (NSString *)kCGImagePropertyJFIFDictionary,
        (NSString *)kCGImagePropertyExifDictionary,
        (NSString *)kCGImagePropertyPNGDictionary,
        (NSString *)kCGImagePropertyIPTCDictionary,
        (NSString *)kCGImagePropertyGPSDictionary,
        (NSString *)kCGImagePropertyRawDictionary,
        (NSString *)kCGImagePropertyCIFFDictionary,
        (NSString *)kCGImageProperty8BIMDictionary,
        (NSString *)kCGImagePropertyDNGDictionary,
        (NSString *)kCGImagePropertyExifAuxDictionary,
    ];
    
    NSMutableDictionary *validMetadata = [NSMutableDictionary dictionary];
    [metadata enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if ([validMetadataKeys containsObject:key]) {
            validMetadata[key] = obj;
        }
    }];
    
    // your CGImage stuff
    
    CGImageDestinationAddImageFromSource(destination, imgSource, 0, (__bridge CFDictionaryRef)validMetadata);
    

提交回复
热议问题