3 Replies
      Latest reply on Aug 22, 2016 5:29 PM by thomas.pintaric
      thomas.pintaric Level 2 Level 2 (55 points)

        I'm using [CIContext writeJPEGRepresentationOfImage:(CIImage*)image ...] to export a CIImage to a JPEG file, which works fine.

        However, when attempting to attach custom EXIF metadata to the image, not all of my custom EXIF tags end up in the JPEG file.

         

        In the (simplified) example below, the "UserComment" EXIF tag ends up getting exported, but the "CustomRendered" EXIF tag does not (!):

         

        CVImageBufferRef imageBuffer = [... our image buffer ...];
        NSMutableDictionary* customImageAttachments = [... obtained from a CMSampleBufferRef ...];
        customImageAttachments[(__bridge NSString*)kCGImagePropertyExifDictionary][(__bridge NSString*)kCGImagePropertyExifCustomRendered] = @"1"; // EXIF tag will NOT end up in the exported JPEG file.
        customImageAttachments[(__bridge NSString*)kCGImagePropertyExifDictionary][(__bridge NSString*)kCGImagePropertyExifUserComment] = @"QWERTY12345"; // EXIF tag will end up in the exported JPEG.
        CIContext* context = [CIContext context];
        CIImage* inputImage = [CIImage imageWithCVImageBuffer:imageBuffer options:@{kCIImageProperties: customImageAttachments}];
        NSURL *temporaryFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", [[NSUUID UUID] UUIDString]]]];
        [context writeJPEGRepresentationOfImage:inputImage
          toURL:temporaryFileURL
          colorSpace:CGColorSpaceCreateWithName(kCGColorSpaceSRGB)
            options:@{ (__bridge NSString*)kCGImageDestinationLossyCompressionQuality : @1.0f}
          error:nil];
        // (Not shown: Create a new PHAsset from JPEG at temporaryFileURL using PHAssetCreationRequest)
        [[NSFileManager defaultManager] removeItemAtURL:temporaryFileURL error:nil];
        

         

        I checked the exported JPEG file with both exiv2 and exiftool, and the "CustomRendered" tag is definitely missing from the file.

        Is there a specific reason for this? Are certain EXIF tags deleted before export? If yes, which ones?