title: Finding the average value of the color red in a BufferedImage (Java)
body: <p>I want find the average red RGB-value of a MyImage (extending BufferedImage). I save the red value for each pixel in the image to an array red[]. At the end I want to sum these ut to find the average value of red. But when I run this code on a MyImage it only prints 0. How can i get this method to work properly? (The code not included here works just fine)</p>
  
  <pre><code>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 &lt; width ; i++)
          {
              for(int j=0; j &lt; 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 &lt; red.length; i++)
              sum += red[i];
  
          int averageRed = sum/red.length;
          System.out.println(averageRed);
      }        
  }
  </code></pre>