这是我的代码。
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) data, NULL);
CFStringRef imageType = CGImageSourceGetType(source);
NSMutableData *resultData = [NSMutableData alloc];
CFDictionaryRef tempp= CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
CGImageDestinationRef imgDest = CGImageDestinationCreateWithData((__bridge `CFMutableDataRef)(resultData), imageType, 1, (__bridge CFDictionaryRef)dictionary);`
现在他们是2回写图像的方法。
- >此方法正在压缩图像的大小,但完美地编写元数据 。
CGImageDestinationAddImageFromSource(imgDest, source, 0, (__bridge CFDictionaryRef)dictionary);
CGImageDestinationFinalize(imgDest);
[resultData writeToFile:[NSURL URLWithString:@"/Users/jamil/Desktop/19nov/DSC_3170a.jpg"].path atomically:YES];
- >另一个不是压缩图像,而是不写元数据。
CGImageDestinationCopyImageSource(imgDest, source, (__bridge CFDictionaryRef)dictionary, NULL);
[resultData writeToFile:[NSURL URLWithString:@"/Users/jamil/Desktop/19nov/DSC_3170a.jpg"].path atomically:YES];
dictionary
格式正确,还包括kCGImageDestinationMergeMetadata
和kCGImageDestinationMetadata
。