确定在AGImagePickerController中select的照片

我正在使用AGImagePickerController 。 我很难搞清楚如何导入select到我的iCarousel在另一个旋转木马的图像。 我知道它的success block包含选定的图像。 我似乎无法将其导入到我的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]; } 

在我的awakeFromNib中:

 - (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; } 

你应该能够使用你的NSLog语句来查看info array的内容。 看到这个日志语句的内容是有帮助的。

我在这里find它,它可能工作:

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

编辑

用户select后,需要保存图像(内存中或者写入文件)。 如果你想写他们的文件,你可以这样做:

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

如果AGImagePickerController代码位于iCarousel类中,则可以将图像添加到images数组中。 你的successBlock看起来像这样:

 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代码中,您需要从图像arrays或磁盘中读取图像(取决于您select保存的位置)。 如果你将它们保存在内存中,你的代码可能如下所示:

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

或者,如果您决定将图像保存到磁盘,则可以使用[UIImage imageWithContentsOfFile:filePath];重新创buildUIImage对象[UIImage imageWithContentsOfFile:filePath];