我有相機覆蓋圖像陣列。當我點擊按鈕時,我需要使用相機視圖拍攝一個疊加圖像的快照。但是當我在設備中啓動時遇到以下錯誤。我搜索了一些現有的代碼,我無法得到答案。'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]];
}
的圖像被顯示在相機的覆蓋圖。當我點擊按鈕捕捉覆蓋圖像時,我得到錯誤。
一次檢查這一個的UIImage *疊加= [UIImage的imageNamed:映像文件名稱]。在這個imageFileName從數組中獲得,但在數組中,你已經添加objectts作爲images.so在這裏兩次分配 – Balu
@Sunny:我沒有得到你。解釋清楚 – Ram
我已經編輯你的代碼一旦檢查它。 – Balu