Ios UIImage的元数据字典未获取IPTC密钥的值
在保存截图图像时,我试图将UIImage对象的元数据更改为图像的自定义标题和描述 导入的标题Ios UIImage的元数据字典未获取IPTC密钥的值,ios,uiimage,metadata,alassetslibrary,Ios,Uiimage,Metadata,Alassetslibrary,在保存截图图像时,我试图将UIImage对象的元数据更改为图像的自定义标题和描述 导入的标题 #import <AssetsLibrary/AssetsLibrary.h> #import <ImageIO/ImageIO.h> #import <ImageIO/CGImageProperties.h> 问题:元数据字典仅包含以下带有键的对象 其中元数据中的kGimagePropertyIptCdictionary是emtpy!请告诉我在哪里可以找到键{I
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>
#import <ImageIO/CGImageProperties.h>
问题:元数据
字典仅包含以下带有键的对象
其中元数据中的kGimagePropertyIptCdictionary
是emtpy!请告诉我在哪里可以找到键{IPTC}
的值
更新:有点晚了,但我是这样做的: 使用class方法创建一个类(我们称之为
MetadataClass
):
+ (void)addMetadata:(NSDictionary *)metadataToAdd toImageDataSampleBuffer:(CMSampleBufferRef)imageDataSampleBuffer
{
// Grab metadata of image
CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);
NSMutableDictionary *imageMetadata = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary *)metadataDict];
CFRelease(metadataDict);
for( NSString *metadataName in metadataToAdd )
{
id metadata = [metadataToAdd valueForKey:metadataName];
if( [metadata isKindOfClass:NSDictionary.class] )
{
NSMutableDictionary *subDict = [imageMetadata valueForKey:metadataName];
if( !subDict )
{
subDict = [NSMutableDictionary dictionary];
[imageMetadata setValue:subDict forKey:metadataName];
}
[subDict addEntriesFromDictionary:metadata];
}
else if( [metadata isKindOfClass:NSString.class] )
[imageMetadata setValue:metadata forKey:metadataName];
else if( [metadata isKindOfClass:NSValue.class] )
[imageMetadata setValue:metadata forKey:metadataName];
}
// set the dictionary back to the buffer
CMSetAttachments(imageDataSampleBuffer, (CFMutableDictionaryRef)imageMetadata, kCMAttachmentMode_ShouldPropagate);
}
我如何使用它:
NSDictionary *iptc = @{
(NSString *)kCGImagePropertyIPTCObjectTypeReference : @"kCGImagePropertyIPTCObjectTypeReference",
(NSString *)kCGImagePropertyIPTCObjectAttributeReference : @"kCGImagePropertyIPTCObjectAttributeReference",
(NSString *)kCGImagePropertyIPTCObjectName : @"kCGImagePropertyIPTCObjectName",
(NSString *)kCGImagePropertyIPTCEditStatus : @"kCGImagePropertyIPTCEditStatus",
(NSString *)kCGImagePropertyIPTCEditorialUpdate : @"kCGImagePropertyIPTCEditorialUpdate",
(NSString *)kCGImagePropertyIPTCUrgency : @"kCGImagePropertyIPTCUrgency",
(NSString *)kCGImagePropertyIPTCSubjectReference : @"kCGImagePropertyIPTCSubjectReference",
(NSString *)kCGImagePropertyIPTCCategory : @"kCGImagePropertyIPTCCategory",
(NSString *)kCGImagePropertyIPTCSupplementalCategory : @"kCGImagePropertyIPTCSupplementalCategory",
(NSString *)kCGImagePropertyIPTCFixtureIdentifier : @"kCGImagePropertyIPTCFixtureIdentifier",
(NSString *)kCGImagePropertyIPTCKeywords : @"kCGImagePropertyIPTCKeywords",
(NSString *)kCGImagePropertyIPTCContentLocationCode : @"kCGImagePropertyIPTCContentLocationCode",
(NSString *)kCGImagePropertyIPTCContentLocationName : @"kCGImagePropertyIPTCContentLocationName",
(NSString *)kCGImagePropertyIPTCReleaseDate : @"kCGImagePropertyIPTCReleaseDate",
(NSString *)kCGImagePropertyIPTCReleaseTime : @"kCGImagePropertyIPTCReleaseTime",
(NSString *)kCGImagePropertyIPTCExpirationDate : @"kCGImagePropertyIPTCExpirationDate",
(NSString *)kCGImagePropertyIPTCExpirationTime : @"kCGImagePropertyIPTCExpirationTime",
(NSString *)kCGImagePropertyIPTCSpecialInstructions : @"kCGImagePropertyIPTCSpecialInstructions",
(NSString *)kCGImagePropertyIPTCActionAdvised : @"kCGImagePropertyIPTCActionAdvised",
(NSString *)kCGImagePropertyIPTCReferenceService : @"kCGImagePropertyIPTCReferenceService",
(NSString *)kCGImagePropertyIPTCReferenceDate : @"kCGImagePropertyIPTCReferenceDate",
(NSString *)kCGImagePropertyIPTCReferenceNumber : @"kCGImagePropertyIPTCReferenceNumber",
(NSString *)kCGImagePropertyIPTCDateCreated : @"kCGImagePropertyIPTCDateCreated",
(NSString *)kCGImagePropertyIPTCTimeCreated : @"kCGImagePropertyIPTCTimeCreated",
(NSString *)kCGImagePropertyIPTCDigitalCreationDate : @"kCGImagePropertyIPTCDigitalCreationDate",
(NSString *)kCGImagePropertyIPTCDigitalCreationTime : @"kCGImagePropertyIPTCDigitalCreationTime",
(NSString *)kCGImagePropertyIPTCOriginatingProgram : <CFBundleName>,
(NSString *)kCGImagePropertyIPTCProgramVersion : <CFBundleVersion>,
(NSString *)kCGImagePropertyIPTCObjectCycle : @"kCGImagePropertyIPTCObjectCycle",
(NSString *)kCGImagePropertyIPTCByline : @"kCGImagePropertyIPTCByline",
(NSString *)kCGImagePropertyIPTCBylineTitle : @"kCGImagePropertyIPTCBylineTitle",
(NSString *)kCGImagePropertyIPTCCity : @"kCGImagePropertyIPTCCity",
(NSString *)kCGImagePropertyIPTCSubLocation : @"kCGImagePropertyIPTCSubLocation",
(NSString *)kCGImagePropertyIPTCProvinceState : @"kCGImagePropertyIPTCProvinceState",
(NSString *)kCGImagePropertyIPTCCountryPrimaryLocationCode : @"kCGImagePropertyIPTCCountryPrimaryLocationCode",
(NSString *)kCGImagePropertyIPTCCountryPrimaryLocationName : @"kCGImagePropertyIPTCCountryPrimaryLocationName",
(NSString *)kCGImagePropertyIPTCOriginalTransmissionReference : @"kCGImagePropertyIPTCOriginalTransmissionReference",
// (NSString *)kCGImagePropertyIPTCHeadline: : @"kCGImagePropertyIPTCHeadline",
(NSString *)kCGImagePropertyIPTCCredit : @"kCGImagePropertyIPTCCredit",
(NSString *)kCGImagePropertyIPTCSource : @"kCGImagePropertyIPTCSource",
(NSString *)kCGImagePropertyIPTCCopyrightNotice : @"kCGImagePropertyIPTCCopyrightNotice",
(NSString *)kCGImagePropertyIPTCContact : @"kCGImagePropertyIPTCContact",
(NSString *)kCGImagePropertyIPTCCaptionAbstract : @"kCGImagePropertyIPTCCaptionAbstract",
(NSString *)kCGImagePropertyIPTCWriterEditor : @"kCGImagePropertyIPTCWriterEditor",
(NSString *)kCGImagePropertyIPTCImageType : @"kCGImagePropertyIPTCImageType",
(NSString *)kCGImagePropertyIPTCImageOrientation : @"kCGImagePropertyIPTCImageOrientation",
(NSString *)kCGImagePropertyIPTCLanguageIdentifier : @"kCGImagePropertyIPTCLanguageIdentifier",
(NSString *)kCGImagePropertyIPTCStarRating : @"kCGImagePropertyIPTCStarRating",
(NSString *)kCGImagePropertyIPTCCreatorContactInfo : @"kCGImagePropertyIPTCCreatorContactInfo",
(NSString *)kCGImagePropertyIPTCRightsUsageTerms : @"kCGImagePropertyIPTCRightsUsageTerms",
(NSString *)kCGImagePropertyIPTCScene : @"kCGImagePropertyIPTCScene",
(NSString *)kCGImagePropertyIPTCContactInfoCity : @"kCGImagePropertyIPTCContactInfoCity",
(NSString *)kCGImagePropertyIPTCContactInfoCountry : @"kCGImagePropertyIPTCContactInfoCountry",
(NSString *)kCGImagePropertyIPTCContactInfoAddress : @"kCGImagePropertyIPTCContactInfoAddress",
(NSString *)kCGImagePropertyIPTCContactInfoPostalCode : @"kCGImagePropertyIPTCContactInfoPostalCode",
(NSString *)kCGImagePropertyIPTCContactInfoStateProvince : @"kCGImagePropertyIPTCContactInfoStateProvince",
(NSString *)kCGImagePropertyIPTCContactInfoEmails : @"kCGImagePropertyIPTCContactInfoEmails",
(NSString *)kCGImagePropertyIPTCContactInfoPhones : @"kCGImagePropertyIPTCContactInfoPhones",
(NSString *)kCGImagePropertyIPTCContactInfoWebURLs : @"kCGImagePropertyIPTCContactInfoWebURLs" };
NSDictionary<NSString *, NSNumber *> *orientation = @{(NSString *)kCGImagePropertyOrientation : <image orientation as NSNumber> };
// Create a new mutable Dictionary and insert the IPTC sub-dictionary and the base orientation property.
NSMutableDictionary *d = [NSMutableDictionary dictionary];
d[(NSString *)kCGImagePropertyIPTCDictionary] = iptc;
[d addEntriesFromDictionary:orientation];
[MetadataClass addMetadata:d toImageDataSampleBuffer:imageDataSampleBuffer];
然后,您可以使用以下方法保存文件:
[jpegData writeToFile:<path of JPEG file> atomically:YES];
[JPEG数据写入文件:原子:是];
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]
[jpegData writeToFile:<path of JPEG file> atomically:YES];