मुझे छवि मेटाडेटा को छवि पर सही ढंग से लिखा नहीं जा सकता है अगर कुंजी/वैल पहले से ही मूल छवि मेटाडेटा में CGImageDestination के साथ मौजूद है। यह ठीक काम करता है अगर यह मूल मेटाडेटा में कुंजी/वैल मौजूद नहीं है।आप छवि मेटाडेटा को कैसे ओवरराइट करते हैं?
यह लगभग है जैसे मूल छवि में छवि मेटाडेटा गुण संशोधनों पर प्राथमिकता लेते हैं। क्या यह किसी प्रकार का बीजान्टिन स्वरूपण मुद्दा है, मुझे पता नहीं है, जहां मुझे किसी असामान्य तरीके से एक बग या कुंजी में कुंजी/वैल को पॉप्युलेट करने की आवश्यकता है? किसी और ने यह देखा?
दोनों मामलों के लिए कोड और आउटपुट, जहां यह ठीक से काम करता है (यदि मान पहले से सेट नहीं है) और लिखने में विफल रहता है (यदि मान पहले से ही किसी अन्य चीज़ पर सेट है)।
किसी भी मदद की सराहना की सराहना की।
वह स्थान है जहां/मैं छवि NSData कैसे बना सकता हूँ:
- (NSData*)writeMetadataIntoImageData:(NSData*)imageData metadata:(NSMutableDictionary*)metadataAsMutable
{
// create an imagesourceref
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) imageData, NULL);
// read and log pre write metadata
NSDictionary* metadata = (NSDictionary *) CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL));
NSLog(@"Before:\n------------------------------%@\n------------------------------", metadata);
// set the new metadata keys here
NSMutableDictionary* iptc = [metadataAsMutable[(NSString*)kCGImagePropertyIPTCDictionary] mutableCopy];
if (!iptc)
{
iptc = [NSMutableDictionary dictionaryWithCapacity:1];
}
iptc[(NSString*)kCGImagePropertyIPTCCaptionAbstract] = @"Hardcoded Caption";
metadataAsMutable[(NSString*)kCGImagePropertyIPTCDictionary] = iptc;
// log the new metadata as we want it written
NSLog(@"Parameter:\n------------------------------%@\n------------------------------", metadataAsMutable);
// this is the type of image (e.g., public.jpeg)
CFStringRef UTI = CGImageSourceGetType(source);
// create a new data object and write the new image into it
NSMutableData *dest_data = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);
if(!destination)
{
NSLog(@"Error: Could not create image destination");
}
// add the image contained in the image source to the destination, overidding the old metadata with our modified metadata
CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) metadataAsMutable);
BOOL success = NO;
success = CGImageDestinationFinalize(destination);
if(!success)
{
NSLog(@"Error: Could not create data from image destination");
}
// read and log post write metadata
CGImageSourceRef source2;
source2 = CGImageSourceCreateWithData((__bridge CFDataRef) dest_data, NULL);
NSDictionary *metadata2 = (NSDictionary *) CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source2,0,NULL));
NSLog(@"After:\n------------------------------%@\n------------------------------", metadata2);
// cleanup
CFRelease(destination);
// return the new data
return dest_data;
}
यहाँ जब छवि एक मौजूदा मूल्य है के लिए NSLogs हैं:
// convert the existing asset to nsdata to overwrite itself
ALAssetRepresentation* rep = [asset defaultRepresentation];
Byte* buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData* imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
// write the metadata directly into the nsdata of the image itself
NSData* newImage = [self writeMetadataIntoImageData:imageData metadata:newMetadata];
यहाँ मेटाडाटा की वास्तविक संशोधन है कुंजी के लिए:
Before:
------------------------------{
<...snip...>
"{IPTC}" = {
"Caption/Abstract" = Blurry;
DateCreated = 20130923;
DigitalCreationDate = 20130923;
DigitalCreationTime = 173815;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 173815;
};
<...snip...>
}
------------------------------
Parameter:
------------------------------{
<...snip...>
"{IPTC}" = {
"Caption/Abstract" = "Hardcoded Caption";
DateCreated = 20130923;
DigitalCreationDate = 20130923;
DigitalCreationTime = 173815;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 173815;
};
<...snip...>
}
------------------------------
After:
------------------------------{
<...snip...>
"{IPTC}" = {
"Caption/Abstract" = Blurry;
DateCreated = 20130923;
DigitalCreationDate = 20130923;
DigitalCreationTime = 173815;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 173815;
};
<...snip...>
}
------------------------------
यहां एनएसएलॉग हैं जब छवि के लिए कुंजी के लिए कोई मूल्य नहीं है :
Before:
------------------------------{
<...snip...>
"{IPTC}" = {
DateCreated = 20130925;
DigitalCreationDate = 20130925;
DigitalCreationTime = 192856;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 192856;
};
<...snip...>
}
------------------------------
Parameter:
------------------------------{
<...snip...>
"{IPTC}" = {
"Caption/Abstract" = "Hardcoded Caption";
DateCreated = 20130925;
DigitalCreationDate = 20130925;
DigitalCreationTime = 192856;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 192856;
};
<...snip...>
}
------------------------------
After:
------------------------------{
<...snip...>
"{IPTC}" = {
"Caption/Abstract" = "Hardcoded Caption";
DateCreated = 20130925;
DigitalCreationDate = 20130925;
DigitalCreationTime = 192856;
Keywords = (
fake
);
SupplementalCategory = (
fake
);
TimeCreated = 192856;
};
<...snip...>
}
------------------------------
मैंने CGImageDestinationCopyImageSource भी कोशिश की, लेकिन यदि आप एक ही फ़ाइल को एक से अधिक बार संपादित करते हैं तो यह जेपीईजी डेटास्ट्रीम को दूषित करता है। ऐप्पल तकनीकी सहायता घटना खोला गया ... –
हैलो स्कॉट! इस पर कोई भी समाचार? मेरी भी यही समस्या है! कृपया मुझे बताओ! – user2452250
इस पोस्ट पर एक नज़र डालें: http://stackoverflow.com/questions/14624384/save-original-image-data-with-modified-metadata-no-re-encoding-on-ios –