当我在IOS8中的标准照片应用程序中使用过滤器时,我无法获得完整的元数据。 我尝试了两种获取元数据的方法:
[manager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
CIImage *ciimage = [CIImage imageWithData:imageData];
NSMutableDictionary *exif = [NSMutableDictionary dictionary];
[exif addEntriesFromDictionary:ciimage.properties];
}];
[asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *cimage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSMutableDictionary *exif = [NSMutableDictionary dictionary];
[exif addEntriesFromDictionary:cimage.properties];
}];
我没有找到任何提及照片的应用程序。我总是得到这样的结果:
{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 1;
PixelHeight = 2592;
PixelWidth = 1936;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 1936;
PixelYDimension = 2592;
};
"{JFIF}" = {
DensityUnit = 1;
JFIFVersion = (
1,
0,
1
);
XDensity = 72;
YDensity = 72;
};
"{TIFF}" = {
Orientation = 1;
};
有没有人找到解决方法如何获取已在照片中编辑过的图像的元数据?
我希望看到这样的元数据:
答案 0 :(得分:2)
我找到了如何获取原始元数据:
PHImageRequestOptions *options = [PHImageRequestOptions new];
options.networkAccessAllowed = YES;
options.synchronous = YES;
options.version = PHImageRequestOptionsVersionOriginal;
[manager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
CIImage *ciimage = [CIImage imageWithData:imageData];
NSMutableDictionary *exif = [NSMutableDictionary dictionary];
[exif addEntriesFromDictionary:ciimage.properties];
}];
答案 1 :(得分:0)
您可以从PHAsset的属性获取创建日期,修改日期。 PHAsset properties
答案 2 :(得分:0)
我已经尝试了完全相同的代码以及其他所有替代机制,以便从XCode IOS 8模拟器中的Photo应用程序中检索原始图像数据,并且我在模拟器下的照片应用程序中的任何图像的唯一回复是几乎是空的EXIF - 几乎与原始问题中说明的相同。
这是一个问题:这只是模拟器吗?是否存在通过拖放将图像添加到模拟器中的Photo应用程序的问题?
PHImageManager.defaultManager().requestImageForAsset(assetImage as PHAsset, targetSize:PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: { (initialResult, _) in
self.photoImageView.image = initialResult as UIImage
println("WTF")
println(initialResult)
})
和这个
PHImageManager.defaultManager().requestImageDataForAsset(assetImage, options: imageRequestOptions, resultHandler: { (imageData: NSData!, dataUti: String!, orientation: UIImageOrientation, _) in
println("requestImageDataForAsset")
println(imageData)
let imageTest = CIImage(data: imageData)
println(imageTest)
let imageMeta = imageTest.properties()
println(imageMeta)
})
和这个
assetImage.requestContentEditingInputWithOptions(initialRequestOptions, completionHandler: { (input: PHContentEditingInput!, _) -> Void in
//Get full image
let url = input.fullSizeImageURL
let orientation = input.fullSizeImageOrientation
var inputImage = CIImage(contentsOfURL: url)
inputImage = inputImage.imageByApplyingOrientation(orientation)
for (key, value) in inputImage.properties() {
println("key: \(key)")
println("value: \(value)")
}
})
在XCode IOS模拟器中为8.0 / 8.1生成相同的结果。
您的代码是否适用于模拟器?它似乎与我提供的第二个样本相同。
答案 3 :(得分:0)
太奇怪了。
NSString *albumName = @"albumName"
PHFetchOptions *fetchOption = [[PHFetchOptions alloc]init];
fetchOption.predicate = [NSPredicate predicateWithFormat:@"title == %@",albumName];
PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:fetchOption];
PHFetchOptions *fetchOption = [[PHFetchOptions alloc]init];
fetchOption.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
fetchOption.predicate = [NSPredicate predicateWithFormat:@"mediaType == 1"];
fetchOption.wantsIncrementalChangeDetails = YES;
PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:[result firstObject] options:nil];
//MetaData here is not complicated as you get
[result[0] requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSDictionary *metaData = [[NSDictionary alloc]initWithDictionary:image.properties];
NSLog(@"metadata: %@", image.properties.description);
}];
使用上面的代码,metaData并不复杂。 然后..
NSString *type = [NSString stringWithFormat:@"mediaType == 1 && (pixelWidth != %f && pixelHeight != %f)",SCREEN_WIDTH*scale,SCREEN_HEIGHT*scale];
allPhotosfetchOption.predicate = [NSPredicate predicateWithFormat:type];
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosfetchOption];
[result[0] requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSDictionary *metaData = [[NSDictionary alloc]initWithDictionary:image.properties];
NSLog(@"metadata: %@", image.properties.description);
}];
在这里,我可以获得完整的元数据...我认为这是Photos.framework的一个错误