Ios ';NSInvalidArgumentException';,原因:'-[UIImage length]:发送到实例0x1d53b6b0'的无法识别的选择器;

Ios ';NSInvalidArgumentException';,原因:'-[UIImage length]:发送到实例0x1d53b6b0'的无法识别的选择器;,ios,objective-c,arrays,nsarray,overlay,Ios,Objective C,Arrays,Nsarray,Overlay,我有一系列的图像在相机上覆盖。当我点击按钮时,我需要用相机视图拍摄一张叠加图像的快照。但我在设备中启动时出现以下错误。我搜索了一些现有的代码,但找不到答案 错误: [UIImage length]: unrecognized selector sent to instance 0x1d53b6b0 2013-04-02 11:27:18.748 ARimage[1166:907] *** Terminating app due to uncaught exception 'N

我有一系列的图像在相机上覆盖。当我点击按钮时,我需要用相机视图拍摄一张叠加图像的快照。但我在设备中启动时出现以下错误。我搜索了一些现有的代码,但找不到答案

错误:

[UIImage length]: unrecognized selector sent to instance 0x1d53b6b0 2013-04-02 11:27:18.748 
    ARimage[1166:907] *** Terminating app due to uncaught exception 
    'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x1d53b6b0'
阵列覆盖图像的代码:

    NSArray *arrayOfImageFiles=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"img1.png"],
[UIImage imageNamed:@"img2.png"],
[UIImage imageNamed:@"img3.png"],
[UIImage imageNamed:@"img4.png"],
[UIImage imageNamed:@"img5.png"], nil];//array of images.

     for(NSString * imageFileName in arrayOfImageFiles)//here you are getting string format but imageFileName is an image object
          {
    UIImage * overlay = [UIImage imageNamed: imageFileName];//here imageFileName is image simply give here  UIImage * overlay=imageFileName;
    if(overlay)
        {

       CGSize overlaySize = [overlay size];                                                                    

       [overlay drawInRect:CGRectMake(30 * xScaleFactor, 100 * yScaleFactor, overlaySize.width * xScaleFactor, overlaySize.height * yScaleFactor)];                                                                  
        } else {                                                                                                                                      
         NSLog( @"could not find an image named %@", imageFileName);   

           }
          }                                                             
        UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();                          
         [self setStillImage:combinedImage];                                                           
           UIGraphicsEndImageContext();                                                     
             [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];                                    

       }];                                                 
        }                          
为按钮单击捕获覆盖图像:

 - (void)ButtonPressed {

    [self captureStillImageWithOverlay:[NSArray arrayWithObjects:[UIImage imageNamed:@"img1.png"],
[UIImage imageNamed:@"img2.png"],
[UIImage imageNamed:@"img3.png"],
[UIImage imageNamed:@"img4.png"],
[UIImage imageNamed:@"img5.png"], nil]];                                                          

         }   
图像将显示在“摄影机覆盖”视图中。当我点击按钮捕捉叠加图像时,我得到一个错误

像这样试试

 NSArray *arrayOfImageFiles=[[NSArray alloc]initWithObjects:[UIImage imageNamed:@"img1.png"],
[UIImage imageNamed:@"img2.png"],
[UIImage imageNamed:@"img3.png"],
[UIImage imageNamed:@"img4.png"],
[UIImage imageNamed:@"img5.png"], nil];//array of images.

     for(NSString * imageFileName in arrayOfImageFiles)//here you are getting string format but imageFileName is an image object
          {
      UIImage * overlay=(UIImage *)imageFileName;
    if(overlay)
        {

       CGSize overlaySize = [overlay size];                                                                    

       [overlay drawInRect:CGRectMake(30 * xScaleFactor, 100 * yScaleFactor, overlaySize.width * xScaleFactor, overlaySize.height * yScaleFactor)];                                                                  
        } else {                                                                                                                                      
         NSLog( @"could not find an image named %@", imageFileName);   

           }
          }                                                             
        UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();                          
         [self setStillImage:combinedImage];                                                           
           UIGraphicsEndImageContext();                                                     
             [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];                                    

       }];                                                 
        }

for
语句:

for(NSString * imageFileName in arrayOfImageFiles)
毫无意义。
arrayOfImageFiles
中的对象是UIImage的实例,而不是
NSString
。在这一行

   UIImage * overlay = [UIImage imageNamed: imageFileName];
您将UIImage作为字符串参数传递,但它永远不会起作用

我认为您需要将代码更改为这样(使用新的数组初始化器语法):


一旦选中这一个UIImage*overlay=[UIImage ImageName:imageFileName];在这个imageFileName中,从数组中获取,但在数组中,您已经将ObjectT添加为图像allocation@Sunny例如我没听懂你的话。解释清楚我已经编辑了你的代码,检查一下。@Sunny:adduiimage*overlay=imageFileName;而是UIImage*overlay=[UIImage ImageName:imageFileName];我是对的吗?是的,这一个正确。再次得到相同的错误。我需要用叠加图像拍照。我使用了avfoundationframework。检查我的按键代码。我还设置了[self captureStillImageWithOverlay:[NSArray arrayWithObjects:[UIImage ImageName:@“img1.png”]、[UIImage ImageName:@“img2.png”]、[UIImage ImageName:@“img3.png”]、[UIImage ImageName:@“img4.png”]、[UIImage ImageName:@“img5.png”]、nil];是否正确?此代码是否正确或错误用于拍摄覆盖快照-(void)按钮按下{[self captureStillImageWithOverlay:[NSArray arrayWithObjects:[UIImage ImageName:@“img1.png”]、[UIImage ImageName:@“img2.png”]、[UIImage ImageName:@“img4.png”]、[UIImage ImageName:@“img5.png”]、nil]]我不知道。这些方法是否需要字符串或图像数组?
NSArray *arrayOfImageFileNames = @[@"img1.png", @"img2.png", @"img3.png", @"img4.png", @"img5.png"];

for (NSString* imageFileName in arrayOfImageFileNames)
{  
    // The rest as per your code
}