Re: [問題] UIImagePicker與CGImageSource的連接方 …
※ 引述《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
推
03/21 04:02, , 1F
03/21 04:02, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):