title: How to convert BufferedImage(RGB) to BufferedImage(ARGB or RGBA)?
body: <p>I'm trying to convert the RGB image produced by the Robot.createScreenCapture function to ARGB image. My goal is to set transparency when the pixel haven't changed between two images but I get black color. As shown in the below image. </p>
  
  <p>For example BufferedImage as created as below:</p>
  
  <pre><code> BufferedImage currImage = robot.createScreenCapture(new Rectangle(x, y, width,height));
  </code></pre>
  
  <p>The following function is intended to create ARGB pixel. </p>
  
  <pre><code>private BufferedImage bufferedImagesEqual(BufferedImage prevImage,
          BufferedImage currImage) {
      boolean changed = false;
      BufferedImage imagePart = new BufferedImage(currImage.getWidth(), currImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
      if (prevImage.getWidth() == currImage.getWidth()
              &amp;&amp; prevImage.getHeight() == currImage.getHeight()) {
  
          for (int x = 0; x &lt; currImage.getWidth(); x++) {
              for (int y = 0; y &lt; prevImage.getHeight(); y++) {
                   int argb =  currImage.getRGB(x, y);
                  if (prevImage.getRGB(x, y) != currImage.getRGB(x, y)){
                  //  return false;
                      //  currImage.setRGB(x, y, 0);
                      if(!changed){
                          changed = true;
                      }
                  }
                  else {
                      imagePart.setRGB(x, y, 0xff000000);
                  }
              }
          }
      } else {
          return imagePart;
      }
      if(changed){
          return imagePart;
      }else {
          return null;
      }
  }
  </code></pre>