title: ArrayIndexOutOfBounds Exception when recreating integer from pixel values
body: <p>I am trying to separate the red, green and blue values in an image and do some permutation on the arrays. After doing the permutation, am trying to write the image but found an exception while writing the pixel values to an integer.</p>
  
  <p>The exception is:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0"   java.lang.ArrayIndexOutOfBoundsException: 272
  
      at encryption.core.receiveFramePath(core.java:203)
  
      at encryption.fny.jButton3ActionPerformed(fny.java:657)
  
      at encryption.fny.access$900(fny.java:14)
  </code></pre>
  
  <p>The java code is: </p>
  
  <pre><code>    public class core {
  
      Random rand = new Random();
  
      public void receiveFramePath(String[] fpath, String key)
      {
          System.out.println("Number of frames to be processed are " + fpath.length);
          System.out.println("Key received is " + key);
          int len;
  
          len = key.length();
          //String part1, part2;
          String part1 = key.substring(0, 2);
          String part2 = key.substring(2, len);
  
          System.out.println("Message to be splitted is " + key);
          System.out.println("The parts are " + part1 + " and " + part2);
  
          int fC ;// this is frmaeCount
          fC = fpath.length;
          System.out.println("  No of strings to be processed are " + fC);
          BufferedImage[] img = new BufferedImage[fC];
          int i;// to run the for loop
          for( i = 0; i &lt; fC; i++ )
          {    
                      // Code to read the image pixel values
  
                      File f = new File(fpath[i]);
                      try {
                                  img[i] = ImageIO.read(f);
                          }
                      catch(Exception e)
                          {
                                  e.printStackTrace();
                          }
                      int[] RGBarray = null;
                      int c = 0;
                      int r = 0;
                      int [][] alphaPixels = null;
                      int [][] redPixels = null;
                      int [][] greenPixels = null;
                      int [][] bluePixels =null;
  
                      c = img[i].getWidth();
                      r = img[i].getHeight();
  
                      //System.out.println(" Width of the image is " + c + " The height of the image is " + r);
                      RGBarray = img[i].getRGB(0,0,c,r,null,0,c);   
  
                      alphaPixels = new int [r][c];
                      redPixels = new int [r][c];
                      greenPixels = new int [r][c];
                      bluePixels = new int [r][c];
                      int ii = 0;// to run inside seperating a loop
  
                      for(int row=0; row&lt;r; row++)
                      {
                         for(int col=0; col&lt;c; col++)
                         {
                        //    alphaPixels[row][col] = ((RGBarray[ii]&gt;&gt;24)&amp;0xff);
                            redPixels[row][col] = ((RGBarray[ii]&gt;&gt;16)&amp;0xff);
                            greenPixels[row][col] = ((RGBarray[ii]&gt;&gt;8)&amp;0xff);
                            bluePixels[row][col] = (RGBarray[ii]&amp;0xff);
                            ii++;
                         }
                      }
                      // code to read the image pixel values ends here
  
                      // Fisher alg starts here
                      // logic for permutation on red pixels
                      for ( int ro = 0; ro &lt; r ; ro++)
                      {
                         int[] arr = new int[c];
  
                         for (int co = 0; co &lt; c; co++)
                         {
                             arr[co] = redPixels[ro][co];
                         }
  
                         int max = arr.length - 1;
                         int min = 0;
                         int rnum;
                         int larr = arr.length - 1;
                         int[] parr = new int[arr.length];// to store the permuted array 
                         int flag = 0;// 'flag' to flag the recurring number
                         int plen = parr.length - 1;
  
                         for(int z = 0 ; z &lt; arr.length ; z++)
                         {
                              rnum = (rand.nextInt((max-min)+1) + min);// roll for the random number
                              parr[plen] = arr[rnum];
                              arr[rnum] = arr[larr];
  
                              larr--;// to reduce the size of the original array
                              plen--;// to make the parr to act like a stack
                              max--;
                         }
                         for(int z = 0; z&lt;arr.length;z++ )
                         {
                             redPixels[ro][z] = parr[z];
                         }
                      } 
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; redPixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; redPixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; redPixels permuatation ends here
  
                      // logic for permutation on GREEEEN pixels
                      // logic for permutation on GREEEEN pixels
                      // logic for permutation on GREEEEN pixels
  
                      for ( int ro = 0; ro &lt; r ; ro++)
                      {
                         int[] arr = new int[c];
  
                         for (int co = 0; co &lt; c; co++)
                         {
                             arr[co] = greenPixels[ro][co];
                         }
  
                         int max = arr.length - 1;
                         int min = 0;
                         int rnum;
                         int larr = arr.length - 1;
                         int[] parr = new int[arr.length];// to store the permuted array 
                         int flag = 0;// 'flag' to flag the recurring number
                         int plen = parr.length - 1;
  
                         for(int z = 0 ; z &lt; arr.length ; z++)
                         {
                              rnum = (rand.nextInt((max-min)+1) + min);// roll for the random number
                              parr[plen] = arr[rnum];
                              arr[rnum] = arr[larr];
  
                              larr--;// to reduce the size of the original array
                              plen--;// to make the parr to act like a stack
                              max--;
                         }
                         for(int z = 0; z&lt;arr.length;z++ )
                         {
                             greenPixels[ro][z] = parr[z];
                         }
                      } 
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; greenPixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; greenPixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; greenPixels permuatation ends here
  
                      for ( int ro = 0; ro &lt; r ; ro++)
                      {
                         int[] arr = new int[c];
  
                         for (int co = 0; co &lt; c; co++)
                         {
                             arr[co] = bluePixels[ro][co];
                         }
  
                         int max = arr.length - 1;
                         int min = 0;
                         int rnum;
                         int larr = arr.length - 1;
                         int[] parr = new int[arr.length];// to store the permuted array 
                         int flag = 0;// 'flag' to flag the recurring number
                         int plen = parr.length - 1;
  
                         for(int z = 0 ; z &lt; arr.length ; z++)
                         {
                              rnum = (rand.nextInt((max-min)+1) + min);// roll for the random number
                              parr[plen] = arr[rnum];
                              arr[rnum] = arr[larr];
  
                              larr--;// to reduce the size of the original array
                              plen--;// to make the parr to act like a stack
                              max--;
                         }
                         for(int z = 0; z&lt;arr.length;z++ )
                         {
                             bluePixels[ro][z] = parr[z];
                         }
                      }
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; bluePixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; bluePixels permuatation ends here
                      // &amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp; bluePixels permuatation ends here
  
                      int rgba;
                      for(int row=0; row&lt;r; row++)
                      {
                          for(int col=0; col&lt;r; col++)
                          {
                              rgba = (alphaPixels[row][col] &amp; 0xff) &lt;&lt; 24 | (redPixels[row][col] &amp; 0xff) &lt;&lt; 16 | (greenPixels[row][col] &amp; 0xff) &lt;&lt; 8 | (bluePixels[row][col] &amp; 0xff);
                              img[i].setRGB(col, row, rgba);
                          }
                      }
                      try{
                          ImageIO.write(img[i], "png", new File("D:/Projects/Problem domains/Ashwini/encrypted/encr_"+i+".png"));
                      }
                      catch(Exception e)
                      {
                          e.printStackTrace();
                      }
              }// for loop
      }// method ends
  }// class ends
  </code></pre>
  
  <p>The exception is at line </p>
  
  <pre><code> rgba = (alphaPixels[row][col] &amp; 0xff) &lt;&lt; 24 | (redPixels[row][col] &amp; 0xff) &lt;&lt; 16 | (greenPixels[row][col] &amp; 0xff) &lt;&lt; 8 | (bluePixels[row][col] &amp; 0xff);
  </code></pre>
  
  <p>What might have gone wrong??</p>