IOS 照片操作(获取信息及修改照片)详解
IOS照片操作(获取信息及修改照片)
最近客户想要一个照片水印,并修改其他内容包括获取位置,和修改事件等,哦,可以的呢,我想起了uiview变UIimage的方法可以的
<spanstyle="font-size:14px;">-(UIImage*)convertViewToImage:(UIView*)v { CGSizes=v.bounds.size; UIGraphicsBeginImageContextWithOptions(s,NO,[UIScreenmainScreen].scale); CGContextRefcontext=UIGraphicsGetCurrentContext(); [v.layerrenderInContext:context]; UIImage*image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); v.layer.contents=nil; returnimage; }</span><spanstyle="font-size:12px;"> </span>
但是加的内容就是照片的时间还有GPS地位,略隐私是不
哼,我想到了UIImagePickerController里面的回调可以拍照片也可以从相册里取出来
<spanstyle="font-size:14px;">-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info{</span>
<spanstyle="font-size:14px;"> //info里面有大文章</span>
<spanstyle="font-size:14px;">}</span>
ok先看拍照,拍照的info里面含有三个参数
<spanstyle="font-size:14px;">UIImagePickerControllerMediaMetadata//详细数据,应有尽有exif吧 UIImagePickerControllerMediaType//类型,jpg,png这类的 UIImagePickerControllerOriginalImage//尺寸</span>
我们所需要的数据就在info[UIImagePickerControllerMediaMetadata]找就可以了。时间什么的贼详细
下一个是从相册拿出来的,相册拿出来的info也是三个,只不过把
UIImagePickerControllerMediaMetadata换成了UIImagePickerControllerReferenceURL看见url亲爹啊,地址。
IOS8出来了新的照片库<Photos/Photos.h>
以前那个ass的不用了,我也不会用哼
<spanstyle="font-size:14px;">PHAsset*asset=[PHAssetfetchAssetsWithALAssetURLs:@[assetURL]options:nil][0];</span>
这就完了?恩,信息都在asset里了。里面信息挺全的,直接拿就好了。
注意我们有时候需要地址里面恰好有地址出来
@property(nonatomic,strong,readonly,nullable)CLLocation*location;
就这个,里面由经纬度,有了经纬度咱们要还原一下住址,开始我以为这个里面是地球坐标,没想到这里已经是符合我们社会主义核心价值观的火星坐标了。
亏我还找办法来转换,这个直接就是放进去等待回调出地址就可以了
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!