2013-04-02 37 views
0

我有相機覆蓋圖像陣列。當我點擊按鈕時,我需要使用相機視圖拍攝一個疊加圖像的快照。但是當我在設備中啓動時遇到以下錯誤。我搜索了一些現有的代碼,我無法得到答案。'NSInvalidArgumentException',原因:' - [UIImage length]:無法識別的選擇器發送到實例0x1d53b6b0'

錯誤:陣列的疊加圖像

[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]];               

     } 

的圖像被顯示在相機的覆蓋圖。當我點擊按鈕捕捉覆蓋圖像時,我得到錯誤。

+0

一次檢查這一個的UIImage *疊加= [UIImage的imageNamed:映像文件名稱]。在這個imageFileName從數組中獲得,但在數組中,你已經添加objectts作爲images.so在這裏兩次分配 – Balu

+0

@Sunny:我沒有得到你。解釋清楚 – Ram

+0

我已經編輯你的代碼一旦檢查它。 – Balu

回答

0

嘗試這樣,

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];          

     }];             
     } 
+0

再次得到相同的錯誤。我需要用疊加圖像拍照。我使用AVFoundation框架。檢查我的按鈕按下代碼。我還設置了[self captureStillImageWithOverlay:[UIImage imageNamed:@「img1.png」],[UIImage imageNamed:@「img1.png」], [ [UIImage imageNamed:@「img4.png」], [UIImage imageNamed:@「img5.png」],nil]];這是對的嗎? – Ram

0

for聲明:

for(NSString * imageFileName in arrayOfImageFiles) 

是沒有意義的。 arrayOfImageFiles中的對象是UIImage的實例,而不是NSString。在這一行

UIImage * overlay = [UIImage imageNamed: imageFileName]; 

你傳遞一個UIImage作爲一個字符串參數,永遠不會工作。

我認爲你需要改變的代碼是這樣的(利用新的數組初始化器的語法):

NSArray *arrayOfImageFileNames = @[@"img1.png", @"img2.png", @"img3.png", @"img4.png", @"img5.png"]; 

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

此代碼是正確的還是錯誤的採取重疊快照 - (void)ButtonPressed {self_customStillImageWithOverlay:[NSArray arrayWithObjects:[UIImage imageNamed:@「img1.png」], [UIImage imageNamed:@「img2.png」 ], [UIImage imageNamed:@「img3.png」], [UIImage imageNamed:@「img4.png」], [UIImage imageNamed:@「img5.png」],nil]]; } – Ram

+0

我不知道。這些方法是否需要一串字符串或圖像? – JeremyP

相關問題