2012-04-11 8 views
-1

私はAGImagePickerControllerを使用しています。私が選択した画像を別のカルーセルにある私のiCarouselにインポートする方法を考え出すのは苦労しています。私はその中にsuccess blockが選択された画像を含んでいることを知っています。私はそれを私のawakeFromNibにインポートするか、それを配列に入れることはできません。私のawakeFromNibでAGImagePickerControllerで選択した写真を決定する

-(IBAction) cameraRoll {AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) { 

     if (error == nil) 
     { 
      NSLog(@"User has cancelled."); 
      [self dismissModalViewControllerAnimated:YES]; 
     } else 
     {  
      NSLog(@"Error: %@", error); 

      // Wait for the view controller to show first and hide it after that 
      double delayInSeconds = 0.5; 
      dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
      dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
       [self dismissModalViewControllerAnimated:YES]; 
      }); 
     } 

     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; 

    } andSuccessBlock:^(NSArray *info) { 
     NSLog(@"Info: %@", info); 
     [self dismissModalViewControllerAnimated:YES]; 

     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; 
    }]; 

    [self presentModalViewController:imagePickerController animated:YES]; 
    [imagePickerController release]; 
} 

:ここ

はAGImagePickerControllerを呼び出す私のコードです

- (void)awakeFromNib 
{  
    if (self) { 

     self.images = [NSMutableArray arrayWithObjects:@"111.jpg", 
         @"112.jpg", 
         @"113.jpg", 
         @"114.jpg", 
         @"115.jpg", 
         @"116.jpg", 
         @"117.jpg", 
         @"118.png", 
         @"119.jpg", 
         @"120.jpg", 
         nil]; 

    } 
} 

その後、私は私のカルーセルのためにこれを実装する:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{ 
    //create a numbered view 
    UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[images objectAtIndex:index]]]; 
    return view; 
} 

答えて

5

あなたはできるはずですあなたのNSLogステートメントを使ってinfo arrayの内容を見てください。そのログステートメントの内容を確認すると便利でした。

私はこのhereを発見し、それがうまくいくかもしれない:

for (i = 0; i < info.count; i++) { 
    ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation]; 
    UIImage * image = [UIImage imageWithCGImage:[rep fullResolutionImage]]; 
} 

編集

ユーザーがそれらを選択した後、あなたは画像(メモリー内またはファイルに書き込むことにより、いずれか)を保存する必要があります。 AGImagePickerControllerコードがあなたのiCarouselクラスである

[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES]; 

場合、あなたは自分のimages配列に画像を追加することができます。あなたがファイルにそれらを書きたい場合、あなたはとても似ていることを行うことができます

self.images = [NSMutableArray new]; 

for (i = 0; i < info.count; i++) { 
    ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation]; 
    UIImage * image = [UIImage imageWithCGImage:[rep fullResolutionImage]]; 
    [self.images addObject:image]; 
} 

をそして最後に、あなたのiCarouselコードで、あなたは(あなたがそれらを保存するために選択した場所に応じて)あなたのイメージ配列からまたはディスクのいずれかから画像を読み取るする必要があります:あなたのsuccessBlockは次のようになります。

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{ 
    return [[UIImageView alloc] initWithImage:[self.images objectAtIndex:index]]; 
} 

それとも、あなたがディスクに画像を保存することを決定した場合、あなたは[UIImage imageWithContentsOfFile:filePath];を使用してUIImageオブジェクトを再作成することができます:あなたはメモリに保存されている場合は あなたのコードは次のようになります。

+0

私はiCarouselのawakeFromNibに入れますか? – Bazinga

+0

このコードは、あなたが提供したコードのsuccessBlockに入ります。あなたのiCarouselコードを見ることなく、私は他の多くであなたを助けることができません。 –

+0

私は自分の答えを編集しました。あなたはもう一度それを確認することを願っています。 – Bazinga

関連する問題