我已经在图像上实现了一个递归函数,它调用它的相邻像素直到条件最终确定,我已经能够成功运行此代码,达到 200x200 图像分辨率,但是当图像大小增加时,它将EXC_BAD_ACCESS
在以下堆栈行___lldb_unnamed_function782$处因错误而崩溃$libicucore.A.dylib。我检查了我的代码并且无法检测到任何错误,可能是由于递归回调函数太多。如果有人有任何想法,请告诉我。
这是我的递归代码:
-(void)magicImageContext:(unsigned char*)data point:(CGPoint)point red:(unsigned char)red green:(unsigned char)green blue:(unsigned char)blue bytesPerPixel:(NSInteger)bytesPerPixel bytesPerRow:(NSInteger)bytesPerRow size:(long long int)size width:(NSInteger)width height:(NSInteger)height maskedData:(unsigned char*)masked_data{
for(int x = point.x-1; x<=point.x+1; x++){
for(int y = point.y-1; y<=point.y+1; y++){
if((x == point.x) && (y == point.y)) {
}
else if((x<0) || (y<0) || (x>=width) || (y>=height)){
}
else if([self checkPixelMarkedAtPoint:CGPointMake(x, y) data:masked_data]){
int byteIndex = (bytesPerRow * y) + x* bytesPerPixel;
CGFloat red2 = (data[byteIndex] );
CGFloat green2 = (data[byteIndex + 1]);
CGFloat blue2 = (data[byteIndex + 2]);
if([self checkColorThresholdWithRed1:red green1:green blue1:blue red2:red2 green2:green2 blue2:blue2]){
NSLog(@"x= %d, y= %d %d",x,y,byteIndex);
//mark pixels on masked image
[self changemaskedData:CGPointMake(x,y) data:masked_data];
[self magicImageContext:data point:CGPointMake(x, y) red:red green:green blue:blue bytesPerPixel:bytesPerPixel bytesPerRow:bytesPerRow size:size width:width height:height maskedData:masked_data]; }
}
}
}
}