Re: [問題] UIImagePicker與CGImageSource的連接方 …

看板MacDev作者 (zonble)時間13年前 (2011/03/21 02:11), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《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
感謝z大,你的作法比我的精緻 :p
03/21 04:02, 1F
文章代碼(AID): #1DXaD7j6 (MacDev)
文章代碼(AID): #1DXaD7j6 (MacDev)