作者zonble (zonble)
看板MacDev
标题Re: [问题] UIImagePicker与CGImageSource的连接方 …
时间Mon Mar 21 02:11:16 2011
※ 引述《Piceman (派斯面)》之铭言:
: image source parameter is nil
: 我现在已经用Assests的方法绕过这限制并得到需要的结果
: 不过,对这限制还是有点不满意
: 请问有办法让CGImageSourceCreateWithURL使用assests取得
: UIImagePicker下,使用者所选择的照片吗?
既然是 AssetsLibrary 使用的 URL,我们就用 AssetsLibrary
framework 去读就好了。基本上我们大概也只会需要几种 EXIF
资讯-照片日期、拍摄地点、以及横直旋转方向,至於相机资讯,
AssetsLibrary 没有提供,不过反正一定是 iOS 装置,这部份
用 UIDevice 去读就好了。
首先 Import 两个 framework:
#import <AssetsLibrary/AssetsLibrary.h>
#import <CoreLocation/CoreLocation.h>
然後:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"info:%@", info);
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if (![type isEqualToString:@"public.image"]) {
return;
// 我们现在只处理照片,先不管影片 :p
}
NSURL *URL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *lib = [[[ALAssetsLibrary alloc] init] autorelease];
[lib assetForURL:URL
resultBlock:^(ALAsset *asset){
CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];
NSLog(@"coordinate:%f %f", location.coordinate.latitude, location.coordinate.longitude);
// 拍摄地点
NSDate *date = [asset valueForProperty:ALAssetPropertyDate];
NSLog(@"date:%@", date);
// 拍摄日期
NSArray *presentations = [asset valueForProperty:ALAssetPropertyRepresentations];
NSLog(@"presentations:%@", presentations);
if ([presentations containsObject:@"public.jpeg"]) {
ALAssetRepresentation *presentation = [asset representationForUTI:@"public.jpeg"];
UIImage *fullResolutionImage = [UIImage imageWithCGImage:presentation.fullResolutionImage];
UIImage *fullScreenImage = [UIImage imageWithCGImage:presentation.fullScreenImage];
// 取得 UIImage 物件,有几个不同尺寸的版本
}
}
failureBlock:^(NSError *error) {
NSLog(@"errror:%@", error);
}];
}
--
zonble.net
cocoa.zonble.net
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.184.113
1F:推 Piceman:感谢z大,你的作法比我的精致 :p 03/21 04:02