2012-04-06 80 views
1

我在應用程序中使用的代碼如何訪問我在相機應用中保存的照片?

[library saveImage:self.capturedImg toAlbum:@"FunCam" withCompletionBlock:^(NSError *error) { 
    if (error!=nil) { 
     NSLog(@"Big error: %@", [error description]); 
    } 
}]; 

現在我想以檢索保存到相冊中的所有照片時,用戶點擊一些按鈕,並顯示在圖像相機應用(默認的應用程序中保存的照片我的自定義相冊在iphone上)顯示

請幫我,我該怎麼做?

在此先感謝

+0

你可以做,以資產庫我沒有任何直接的聯繫現在,但我相信它可以使用資產庫來完成... 谷歌爲它,你就會得到它容易 – 2012-04-06 08:38:14

+1

一個示範項目,在這裏使用ALAssets https://github.com/elc/ELCImagePickerController – Aravindhan 2012-04-06 09:01:54

+0

elsimagepickerController是非常有用的在ig之後給我ot從下面回答圖像我感謝你@Aravindhanarvi – 2012-04-07 06:26:40

回答

4

嘗試這些方法...

-(void)loadNewLibraryImages 
{ 
    self.assetGroups = [[NSMutableArray alloc] init]; 
    // Group enumerator Block 
    dispatch_async(dispatch_get_main_queue(),^
        {  
         void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
         { 
          if (group == nil) 
          { 
           return; 
          } 
          if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"YOUR ALBUM NAME"]) { 
           [self.assetGroups addObject:group];        
           [self loadImages]; 
           return; 
          }       

          if (stop) { 
           return; 
          } 

         }; 

         // Group Enumerator Failure Block 
         void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) { 

          UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"No Albums Available"] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
          [alert show]; 
          [alert release]; 
         }; 

         // Enumerate Albums 
         ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];   
         [library enumerateGroupsWithTypes:ALAssetsGroupAll 
               usingBlock:assetGroupEnumerator 
              failureBlock:assetGroupEnumberatorFailure]; 


        }); 


} 

-(void)loadImages 
{ 
    //for (ALAssetsGroup *assetGroup in self.assetGroups) { 
// for (int i = 0; i<[self.assetGroups count]; i++) { 

     ALAssetsGroup *assetGroup = [self.assetGroups objectAtIndex:0]; 
     NSLog(@"ALBUM NAME:;%@",[assetGroup valueForProperty:ALAssetsGroupPropertyName]); 

     [assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) 
     {   
     if(result == nil) 
     { 
     return; 
     } 
      UIImage *img = [UIImage imageWithCGImage:[[result defaultRepresentation] fullScreenImage] scale:1.0 orientation:(UIImageOrientation)[[result valueForProperty:@"ALAssetPropertyOrientation"] intValue]];   

     }]; 

// } 
} 

希望他們將幫助....

+0

謝謝,我會給你關於它的工作或任何錯誤的報告。現在我就可以在我的應用程序應用 – 2012-04-06 10:01:07

+0

是[自loadAssets]是新的功能,我要提出? – 2012-04-06 11:22:28

+0

因爲那是[self loadImages]; – 2012-04-06 11:28:16

相關問題