2

我正在使用 ALAssetsLibrary 将任意 UIImage 写入相机胶卷:

    NSMutableDictionary exifAttachments = [[NSMutableDictionary alloc] init];
        }

        [exifAttachments setValue:[NSNumber numberWithInt:imgWidth] forKey:(NSString*)kCGImagePropertyExifPixelXDimension]; //OK
        [exifAttachments setValue:[NSNumber numberWithInt:imgHeight] forKey:(NSString*)kCGImagePropertyExifPixelYDimension]; //OK
        [exifAttachments setValue:[NSDate date] forKey:(NSString*)kCGImagePropertyExifDateTimeDigitized]; //NOT OK

    _assetsLibrary writeImageToSavedPhotosAlbum:[img CGImage] metadata:exifAttachments completionBlock:^(NSURL *assetURL, NSError *error) {
            NSLog(@"Big error: %@", [error description]);
        }];

这适用于某些参数,但所有与相机相关的参数,如“时间数字化”、“白平衡”等都将被忽略。我的代码有问题吗?如何手动添加相机特定的 EXIF 元数据?

[编辑] 我自己找到了解决方案。对于所有 EXIF 数据,必须添加 child-NSDictionary:

    [exifAttachments setObject:[NSMutableDictionary dictionaryWithCapacity:1] forKey:(NSString*)kCGImagePropertyExifDictionary];

向这个孩子添加数据时,一切正常。

问候,

4

1 回答 1

0

见上面的编辑:

[exifAttachments setObject:[NSMutableDictionary dictionaryWithCapacity:1] forKey:(NSString*)kCGImagePropertyExifDictionary];
于 2012-05-27T13:20:03.483 回答