由于我对iOS开发非常陌生,我试图将图像库中的uiimage添加到数组中。但是当我尝试使用数组向uiimageview添加图像时,它会显示错误
[UIImage stringByDeletingPathExtension]:发送到的无法识别的选择器 实例0x7fefd3ea02f0。
choosen_Imgae = info[ UIImagePickerControllerOriginalImage];
//
// choosen_Imgae = [self resizeImage:choosen_Image];
NSLog(@"chosen image %@",choosen_Imgae);
[picker dismissViewControllerAnimated:YES completion:NULL];
NSData *dataImage = [[NSData alloc] init];
dataImage = UIImagePNGRepresentation(choosen_Imgae);
if (dataImage != nil) {
[image_Arr insertObject:choosen_Imgae atIndex:indexxpath.row];
NSLog(@"image array after adding object %@",image_Arr);
}
答案 0 :(得分:0)
兄弟只需将图像添加到阵列中即可。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *choosen_Imgae=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[image_Arr addObject:image];
[picker dismissViewControllerAnimated:YES completion:nil];
}
如果你在didFinishPickingMediaWithInfo中使用NSData,那么它是一个很长的过程(image-> NSData)。当再次从数组中取出图像时,你必须将NSData转换为图像。所以你可以直接将图像保存到数组中。 您也不需要将insertObject用于数组。
从数组中获取图像时
for (int i=0; i<[image_Arr count]; i++)
{
UIImage *fetch_Image = [image_Arr objectATIndex:i];
imageView.image = fetch_Image;
}