我已经定义了一个递归方法(至少我相信它是递归的),它返回 void 并想在另一个方法中调用它,但不知道如何。我知道这是非常基本的,但有人可以帮忙吗?谢谢。
递归方法:
private static void recursiveWhiteToBlack(BufferedImage image, int width, int height){
image.getRaster().setPixel(width,height, new int [] {0, 0, 0, 0, 0, 0});
int[][] neighbors = neighborsXY(width,height);
for(int i = 0; i<neighbors.length; i++){
int neighborX = neighbors[i][0];
int neighborY = neighbors[i][1];
int[] neighborColor = image.getRaster().getPixel(neighborX, neighborY, new int[] {0, 0, 0, 0, 0, 0});
if(neighborColor[0] == 1){
recursiveWhiteToBlack(image, neighborX, neighborY);
}
}
}
调用它:
public static BufferedImage countObjects(BufferedImage image, BufferedImage original, ComponentPanel panel){
BufferedImage target = copyImage(image);
for(int width=1; width<image.getRaster().getWidth()-1; width++){ //Determine the dimensions for the width (x)
for(int height=1; height<image.getRaster().getHeight()-1; height++){ //Determine the dimensions for the height (y)
int[] pixel = image.getRaster().getPixel(width, height, new int[] {0, 0, 0, 0, 0, 0});
if(pixel[0] == 1){
none = recursiveWhitetoBlack(image, width, height); //HOW TO CALL IT HERE!!!//
}
System.out.println("countObjects method called");
return target;
}