IOS 获取 文件(UIImage) 创建时间
2024-08-23 06:09:44
Image 在手机里 如果是手机拍的那么能使用ALAssetsLibrary获取一系列 图片的信息 颜色、GPS、尺寸、创建日期等
使用ALAssetsLibrary导入框架AssetsLibrary.framework 引入头文件
#import <AssetsLibrary/AssetsLibrary.h>
以手机相册为例代码如下:(获取gps里面时间戳为例)
#pragma -mark UIImagePickerController delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
chosenImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// 指定回调方法 [picker dismissViewControllerAnimated:YES completion:NULL];
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library assetForURL:assetURL resultBlock:^(ALAsset *asset) { NSDictionary* imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata]; NSDictionary *GPSDict=[imageMetadata objectForKey:@"{GPS}"]; NSLog(@"时间:DateStamp:%@",[GPSDict objectForKey: @"DateStamp"]); } failureBlock:^(NSError *error) { }];
}
当手机上同步的照片 和手机自身截图 我却发现字典里面没有创建日期或者GPS的相关信息了
我找到一个方法只要是手机的图片,就可以获取图片创建日期的方法。其他相关的信息以后用到再深究。
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSDate* date = [asset valueForProperty:ALAssetPropertyDate];
NSLog(@"date:%@",date);
}
failureBlock:^(NSError *error) {
}];
其二,当图片以文件形式在沙盒里面的话,主要就是根据文件路径来解决
最新文章
- C#中5步完成word文档打印的方法
- Linux入侵检测常用命令
- easyui datagrid 没数据时显示滚动条的解决方法
- 小白详细讲解快速幂--杭电oj2035-A^B
- 《慕客网:IOS基础入门之Foundation框架初体验》学习笔记 <;五>; NSDicionary + NSMutableDictionary
- python 反模式
- Java RGB数组图像合成 ImageCombining (整理)
- Android(java)学习笔记229:服务(service)之绑定服务调用服务里面的方法 (采用接口隐藏代码内部实现)
- Aptana Studio 快捷键
- Android SDK Manager 无法更新SDK
- C++程序设计实践指导1.12数组中数据线性变换改写要求实现
- DataNode连接错误Retrying connect to server
- FWT模板
- 剑指offer——python【第36题】两个链表的第一个公共结点
- 剑指Offer 2. 替换空格 (字符串)
- python之路——10
- Ubuntu 18.04 安装中文输入法ibus
- VIM编辑器和VI编辑器的区别
- HTTP 1.0 Status Code Definitions
- idea 安装mybatis plugin (mybatis插件)