在 AGImagePickerController 中确定选中的照片 [英] Determine selected photos in AGImagePickerController
问题描述
我正在使用 AGImagePickerController
.我很难弄清楚如何将选定的图像导入另一个轮播中的 iCarousel
.我知道其中的 success block
包含所选图像.我似乎无法将它导入我的 awakeFromNib
或将其放入数组中.
I'm using AGImagePickerController
. Im having a hard time figuring out how to import the images selected into my iCarousel
which is in another carousel. I know that the success block
in it contains the selected image. I can't seem to import it in my awakeFromNib
or putting it in an array.
这是我调用 AGImagePickerController 的代码:
here is my code that calls the 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中:
In my 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];
}
}
然后我为我的轮播实现了这个:
Then I implement this for my carousel :
- (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 数组
的内容.查看该日志语句的内容会很有帮助.
You should be able to look at the contents of the info array
using your NSLog statement. It would have been helpful to see the contents of that log statement.
我在这里找到了这个,它可能有用:
I found this here and it might work:
for (i = 0; i < info.count; i++) {
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage * image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
}
编辑:
在用户选择图像后,您需要保存图像(在内存中或通过将它们写入文件).如果你想将它们写入文件,你可以这样做:
You need to save the images (either in memory or by writing them to files) after the user selects them. If you want to write them to files, you can do that like so:
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
如果 AGImagePickerController 代码在您的 iCarousel
类中,您只需将图像添加到您的 images
数组中即可.你的 successBlock
看起来像这样:
If the AGImagePickerController code is in your iCarousel
class, you can just add the images to your images
array. Your successBlock
would look something like this:
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 代码中,您需要从图像数组或磁盘中读取图像(取决于您选择的保存位置).如果您将它们保存在内存中您的代码可能如下所示:
And finally, in your iCarousel code you need to read the images either from your images array or from the disk (depending on where you chose to save them). If you are saving them in memory your code could look like this:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
return [[UIImageView alloc] initWithImage:[self.images objectAtIndex:index]];
}
或者,如果您决定将图像保存到磁盘,那么您可以使用 [UIImage imageWithContentsOfFile:filePath];
重新创建 UIImage 对象.
Or, if you decided to save the images to disk then you could recreate the UIImage objects using [UIImage imageWithContentsOfFile:filePath];
.
这篇关于在 AGImagePickerController 中确定选中的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!