[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:saveImage];
if (_collection) {
PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:_collection];
[assetCollectionChangeRequest addAssets:@[[assetChangeRequest placeholderForCreatedAsset]]];
}
} completionHandler:^(BOOL success, NSError *error) {
if (!success)
{
NSLog(@"Error creating asset: %@", error);
}
}];
我使用上面的代码,我在相机胶卷中得到了一张奇怪的照片,如照片1。
但是当我用VSCO或snapseed打开保存的照片时,我可以获得正常版本,这是我保存的正确版本。
这是苹果相机胶卷的错误吗?
很奇怪它看起来不错如果我将inputData直接保存到照片库,但添加元数据后,系统照片应用程序中的照片看起来不清楚。
-(NSData*)getDataOfImage:(UIImage *)image
metaData:(NSDictionary *)metaData
{
NSData *inputData = UIImageJPEGRepresentation(image,1.0);
CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef) inputData,nil);
NSMutableData *outputData = [NSMutableData new];
CFStringRef UTI = CGImageSourceGetType(imageSource);
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) outputData, UTI, 1, NULL);
CGImageDestinationAddImageFromSource (imageDestination, imageSource, 0, (__bridge CFMutableDictionaryRef)metaData);
BOOL result = CGImageDestinationFinalize(imageDestination);
if (result == YES) {
NSLog(@"success: save MetaData");
}else{
NSLog(@"failed :save MetaData ");
}
CFRelease(imageSource);
CFRelease(UTI);
CFRelease(imageDestination);
return outputData;
}
答案 0 :(得分:0)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
//NSString *temporaryPath = [cachesDir stringByAppendingString:@"temp"];
NSString *temporaryPath = [cachesDir stringByAppendingString:@"temp.jpg"];
非常奇怪......添加扩展类型后,使用photos.framework PHAssetChangeRequest可以正常保存它的分辨率。 似乎默认保存扩展类型是PNG ...而不是JPG ...
答案 1 :(得分:0)
默认情况下,PHPhotoLibrary将图像保存为jpeg,压缩系数为0.8。 为了获得更好的质量,请自己创建图像(例如系数为0.95),然后使用creationRequestForAssetFromImage(atFileURL :)而不是creationRequestForAsset(from:)。