imagePickerController 获取图片的拍照时间等信息
2016-03-03 10:08
423 查看
imagePickerController 获取图片的拍照时间等信息
//当我们选中图片的时候进入的代理//其实这里图片,照相机共用一个代理-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{ UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage]; UIButton *tempButton = (UIButton *)[self.view viewWithTag:flagImageButton]; [tempButton setBackgroundImage:image forState:UIControlStateNormal]; NSLog(@"info == %@",info); NSData *tempImageData = UIImageJPEGRepresentation(image, 0.5); [self.imageDataArray addObject:image]; if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Recover the snapped image UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //元数据 NSDictionary *dict = [info objectForKey:UIImagePickerControllerMediaMetadata]; NSMutableDictionary *metadata=[NSMutableDictionarydictionaryWithDictionary:dict]; //EXIF数据 NSMutableDictionary *EXIFDictionary =[[metadata objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy]; NSLog(@"EXIFDictionary==%@",EXIFDictionary); NSLog(@"DateTimeDigitized哈哈哈哈==%@",[EXIFDictionary objectForKey:@"DateTimeDigitized"]); NSString *tempTimeChuo = [ViewControllerFactory fromTimeToChui:[EXIFDictionary objectForKey:@"DateTimeDigitized"]]; [self.timeChuoArray addObject:tempTimeChuo]; // Save the image to the album //UIImageWriteToSavedPhotosAlbum(image, self, @selector(imagedidFinishSavingWithError:contextInfo:), nil); UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); NSLog(@"拍照的"); [selfdismissViewControllerAnimated:YEScompletion:nil]; } elseif (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL]; ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init]; [library assetForURL:assetURL resultBlock:^(ALAsset *asset) { NSLog(@"asset===%@",asset); //查看资源的创建时间 NSLog(@"ALAssetPropertyDate:%@",[asset valueForProperty:ALAssetPropertyDate]); NSString *tempTimeChuo = [ViewControllerFactory fromTimeToChui:[asset valueForProperty:ALAssetPropertyDate]]; [self.timeChuoArray addObject:tempTimeChuo]; } failureBlock:^(NSError *error) { }]; [picker dismissViewControllerAnimated:YEScompletion:^{ }]; }
//当我们选中图片的时候进入的代理//其实这里图片,照相机共用一个代理-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{ UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage]; UIButton *tempButton = (UIButton *)[self.view viewWithTag:flagImageButton]; [tempButton setBackgroundImage:image forState:UIControlStateNormal]; NSLog(@"info == %@",info); NSData *tempImageData = UIImageJPEGRepresentation(image, 0.5); [self.imageDataArray addObject:image]; if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Recover the snapped image UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //元数据 NSDictionary *dict = [info objectForKey:UIImagePickerControllerMediaMetadata]; NSMutableDictionary *metadata=[NSMutableDictionarydictionaryWithDictionary:dict]; //EXIF数据 NSMutableDictionary *EXIFDictionary =[[metadata objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy]; NSLog(@"EXIFDictionary==%@",EXIFDictionary); NSLog(@"DateTimeDigitized哈哈哈哈==%@",[EXIFDictionary objectForKey:@"DateTimeDigitized"]); NSString *tempTimeChuo = [ViewControllerFactory fromTimeToChui:[EXIFDictionary objectForKey:@"DateTimeDigitized"]]; [self.timeChuoArray addObject:tempTimeChuo]; // Save the image to the album //UIImageWriteToSavedPhotosAlbum(image, self, @selector(imagedidFinishSavingWithError:contextInfo:), nil); UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); NSLog(@"拍照的"); [selfdismissViewControllerAnimated:YEScompletion:nil]; } elseif (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL]; ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init]; [library assetForURL:assetURL resultBlock:^(ALAsset *asset) { NSLog(@"asset===%@",asset); //查看资源的创建时间 NSLog(@"ALAssetPropertyDate:%@",[asset valueForProperty:ALAssetPropertyDate]); NSString *tempTimeChuo = [ViewControllerFactory fromTimeToChui:[asset valueForProperty:ALAssetPropertyDate]]; [self.timeChuoArray addObject:tempTimeChuo]; } failureBlock:^(NSError *error) { }]; [picker dismissViewControllerAnimated:YEScompletion:^{ }]; }
相关文章推荐
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- upload上传单张图片
- 图片引发的溢出危机(图)
- 计算机信息处理
- 解析MYSQL显示表信息的方法
- C#实现把彩色图片灰度化代码分享
- C#将图片和字节流互相转换并显示到页面上
- C#获取进程或线程相关信息的方法
- C#监控文件夹并自动给图片文件打水印的方法
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- 如何使用C#从word文档中提取图片
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- C#图片添加水印的实现代码
- 随鼠标移动的图片或文字特效代码
- CSS 图片横向排列实现代码
- C#实现将Email地址转成图片显示的方法
- C#实现图片加相框的方法
- 超级经典一套鼠标控制左右滚动图片带自动翻滚
- 用css实现图片垂直居中的使用技巧