title: Converting an array to image Java
body: <p>I would like to convert an array of pixels to images so that I can read each pixel of the image, I've converted the image to pixels and now what I'm trying to do is that I have a picture of an RGB circle , After converting the image to pixels I want to draw images again but Not the entire picture again , I want to draw the red circle alone , the green circle alone and the blue circle alone and store the images in a file , how can that be done ?</p>
  <p>Here's the code that I used to convert the image to array pixels :</p>
  <pre><code>import javax.imageio.ImageIO;
  import java.awt.*;
  import java.awt.image.BufferedImage;
  import java.awt.image.ImageObserver;
  import java.awt.image.PixelGrabber;
  import java.io.File;
  import java.io.IOException;
  
  public class BMPtoArray {
  public static int[] convertToPixels(Image img) {
      int width = img.getWidth(null);
      int height = img.getHeight(null);
      int[] pixel = new int[width * height];
  
      PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, pixel, 0, width);
      try {
          pg.grabPixels();
      } catch (InterruptedException e) {
          throw new IllegalStateException(&quot;Error: Interrupted Waiting for Pixels&quot;);
      }
      if ((pg.getStatus() &amp; ImageObserver.ABORT) != 0) {
          throw new IllegalStateException(&quot;Error: Image Fetch Aborted&quot;);
      }
      return pixel;
  }
  public static void main(String[] args) throws IOException {
      BufferedImage image = ImageIO.read(new File(&quot;C:\\Users\\Mhamd\\Desktop\\3rd year 
  first semester\\Analysis and Coding\\labs\\2.2Java\\src\\circleRGB.bmp&quot;));
      //System.out.println(convertToPixels(image));
  }
  }
  </code></pre>
  <p>Here's the image :</p>
  <p><a href="https://i.stack.imgur.com/e3G2u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e3G2u.png" alt="RGBCirle" /></a></p>
  <p>so this is basically what I'm trying to achieve</p>
  <p>[![This is what I want to Achieve][2]][2]</p>