2
我在圖像上實現了一個遞歸函數,它調用其相鄰像素,直到條件完成,我已經能夠成功運行此代碼,最高分辨率爲200x200,但當圖像大小增加時,將在下面的堆棧行中出現EXC_BAD_ACCESS
錯誤___ lldb_unnamed_function782 $$ libicucore.A.dylib。我檢查了我的代碼,無法檢測到任何錯誤,可能是因爲遞歸回調函數太多。如果有人有任何想法,請讓我知道。在大圖像分辨率下執行時出現EXC_BAD_ACCESS錯誤
這是我的遞歸代碼:
-(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]; }
}
}
}
}
如果你解決了這個問題,你可以粘貼代碼嗎? – Levi