2
[[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;
}
4

2 回答 2

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 ...

于 2015-07-28T08:53:54.333 回答
0

默认情况下,PHPhotoLibrary 将图像保存为压缩系数为 0.8 的 jpeg。为了获得更好的质量,自己创建图像(例如系数为 0.95)并使用 creationRequestForAssetFromImage(atFileURL:) 而不是 creationRequestForAsset(from:)。

于 2020-09-14T22:22:30.110 回答