递归函数
void flood_array8(int x, int y, int width, int height,unsigned char * buf) { if(x >= 0 && x < height && y >= 0 && y < width && buf[x * width + y] == 4) { num+=1; buf[x * width + y] = 99;//标记被泛洪的像素 flood_array8(x + 1, y, width, height, buf); flood_array8(x - 1, y, width, height, buf); flood_array8(x, y + 1, width, height, buf); flood_array8(x, y - 1, width, height, buf); flood_array8(x + 1, y + 1, width, height, buf); flood_array8(x - 1, y - 1, width, height, buf); flood_array8(x - 1, y + 1, width, height, buf); flood_array8(x + 1, y - 1, width, height, buf); } }
很荣幸来到这里参观!