//惨痛经历,,,
- (void)saveToAlbumWithImage:(UIImage*)image
completionBlock:(void (^)(NSURL *assetURL))completionBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
NSData* pngData = UIImagePNGRepresentation(image);
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge_retained CFDataRef)pngData, NULL);
NSDictionary *metadata = (__bridge NSDictionary *)(CGImageSourceCopyPropertiesAtIndex(source, 0, NULL));
NSMutableDictionary *metadataAsMutable = [[NSMutableDictionary dictionaryWithDictionary:metadata] mutableCopy];
//For EXIF Dictionary
NSMutableDictionary *EXIFDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];
if(!EXIFDictionary)
EXIFDictionary = [NSMutableDictionary dictionary];
[EXIFDictionary setObject:@"200x300-1....." forKey:(NSString*)kCGImagePropertyExifUserComment];
//add our modified EXIF data back into the image’s metadata
[metadataAsMutable setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
CFStringRef UTI = CGImageSourceGetType(source);
NSMutableData *dest_data = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data, UTI, 1, NULL);
if(destination)
{
CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef) metadataAsMutable);
BOOL success = CGImageDestinationFinalize(destination);
if(success)
{
// CIImage *testImage = [CIImage imageWithData:dest_data];
//
// NSDictionary *propDict = [testImage properties];//////////............由此应可知以上无误,,,,,,,
//
// UIImage *newImage = [UIImage imageWithData:dest_data];
// NSData* pngData1 = UIImagePNGRepresentation(newImage);
//
// CGImageSourceRef source1 = CGImageSourceCreateWithData((CFDataRef)pngData1, NULL);
// NSDictionary *metadata1 = (__bridge NSDictionary *)(CGImageSourceCopyPropertiesAtIndex(source1, 0, NULL));
//
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
ALAssetsLibrary *assets1Library = [[ALAssetsLibrary alloc] init];
////////metadataAsMutable.............定位到问题,,,,,,,
//////............衡量标准,,,,,,,,,,,,,.......
[assets1Library saveImage:image.CGImage metadata:metadataAsMutable toAlbum:appName completion:^(NSURL *assetURL, NSError *error) {//////...........苹果的角度..,,,,,,,,
completionBlock(assetURL);
if(destination)
CFRelease(destination);
CFRelease(source);
} failure:failureBlock];
}
}
}