How to save a TIFF photo from AVFoundations captureStillImageAsynchronouslyFromConnection to a file with EXIF metadata on an iPhone (iOS)?

前端 未结 2 1425
后悔当初
后悔当初 2021-01-03 11:28

With this question I only ask for the possibilities I have with Xcode and iOS without external libraries. I am already exploring the possibility of using libtiff

2条回答
  •  悲哀的现实
    2021-01-03 11:41

    As you've already cracked 1, 3 and 4, it seems the only hurdle you're missing is saving the data and metadata together. Try this (assuming the unprocessed data is in a CMSampleBufferRef called myImageDataSampleBuffer and you've done the heavy lifting of putting the graphical data into a CGImageRef called myImage):

    CFDictionaryRef metadata = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
      myImageDataSampleBuffer,
      kCMAttachmentMode_ShouldPropagate);
    NSFileManager* fm = [[NSFileManager alloc] init];
    NSURL* pathUrl = [fm URLForDirectory:saveDir
      inDomain:NSUserDomainMask
      appropriateForURL:nil
      create:YES
      error:nil];
    NSURL* saveUrl = [pathUrl URLByAppendingPathComponent:@"myfilename.tif"];
    CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)saveUrl,
      (CFStringRef)@"public.tiff", 1, NULL);
    CGImageDestinationAddImage(destination, myImage, metadata);
    CGImageDestinationFinalize(destination);
    CFRelease(destination);
    

提交回复
热议问题