MyImage(BufferedImageを拡張)の平均赤RGB値を見つけたい。画像内の各ピクセルの赤の値を配列 red[] に保存します。最後に、これらの ut を合計して、赤の平均値を見つけたいと思います。しかし、このコードを MyImage で実行すると、0 しか出力されません。このメソッドを正しく動作させるにはどうすればよいですか? (ここに含まれていないコードは問題なく動作します)
public class MyImage extends BufferedImage {
public MyImage(int width, int height, int imageType) {
super(width, height, imageType);
}
public void findAverageRedValue(){
int height = this.getHeight();
int width = this.getWidth();
int[] red = new int[height*width];
Map m = new HashMap();
for(int i=0; i < width ; i++)
{
for(int j=0; j < height ; j++)
{
ColorModel colorModel = this.getColorModel();
int rCol = colorModel.getRed(j*i);
red[red.length - 1] = rCol;
}
}
int sum = 0;
for(int i = 0; i < red.length; i++)
sum += red[i];
int averageRed = sum/red.length;
System.out.println(averageRed);
}
}