php 取得图片gps,ios - 如何通过Photokit保存图片(带有关于定位GPS的Metadata信息)到相册?...

我通过以下2种方法将有关位置的metadata信息写入照片:

将位置信息写入image,让后调用系统api将图片保存到相册

- (void)writeImageDataToSavedPhotosAlbum:(NSData *)imageData metadata:(NSDictionary *)metadata resultBlock:(PHAssetAssetBoolBlock)resultBlock

{

__block PHObjectPlaceholder *placeholderAsset = nil;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

UIImage *image = [self imageWithData: imageData metadata:metadata];

[PHAssetChangeRequest creationRequestForAssetFromImage: image];

placeholderAsset = newAssetRequest.placeholderForCreatedAsset;

} completionHandler:^(BOOL success, NSError *error) {

if(success){

PHAsset *asset = [self getAssetFromlocalIdentifier:placeholderAsset.localIdentifier];

completionBlock(asset, YES);

} else {

completionBlock(nil, NO);

}

}];

}

- (UIImage *)imageWithData:(NSData *)imageData metadata:(NSDictionary *)metadata

{

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);

NSMutableDictionary * sourceDic = [NSMutableDictionary dictionary];

NSDictionary *source_metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyProperties(source, NULL));

[sourceDic addEntriesFromDictionary: metadata];

[sourceDic addEntriesFromDictionary:source_metadata];

NSMutableData *dest_data = [NSMutableData data];

CFStringRef UTI = CGImageSourceGetType(source);

CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data, UTI, 1,NULL);

CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)sourceDic);

CGImageDestinationFinalize(destination);

CFRelease(source);

CFRelease(destination);

return [UIImage imageWithData: dest_data];

}

2.用PHAssetChangeRequest的location属性保存,代码如下:

+(void)saveImageToCameraRoll:(UIImage*)image location:(CLLocation*)location completionBlock:(PHAssetAssetBoolBlock)completionBlock{

__block PHObjectPlaceholder *placeholderAsset = nil;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

PHAssetChangeRequest *newAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];

newAssetRequest.location = location;

newAssetRequest.creationDate = [NSDate date];

placeholderAsset = newAssetRequest.placeholderForCreatedAsset;

} completionHandler:^(BOOL success, NSError *error) {

if(success){

PHAsset *asset = [self getAssetFromlocalIdentifier:placeholderAsset.localIdentifier];

completionBlock(asset, YES);

} else {

completionBlock(nil, NO);

}

}];

}

然后获取照片的metadata信息,发现没有关于GPS的信息,获取方法如下:

- (void)getPhotoMetadataWithAsset:(PHAsset *)asset

{

PHImageRequestOptions *request = [PHImageRequestOptions new];

request.version = PHImageRequestOptionsVersionCurrent;

request.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

request.resizeMode = PHImageRequestOptionsResizeModeNone;

request.synchronous = YES;

[[PHImageManager defaultManager] requestImageDataForAsset:asset options: request resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);

if (NULL != source) {

NSDictionary * metadataDic = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, 0, NULL));

NSLog(@"metada:%@",metadataDic);

CFRelease(source);

}

}];

}

麻烦看下是保存metadata过程有问题?还是获取metadata有问题?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值