title: How to set bitmap to ARGB_8888 in android?
body: <p>In my android project, I load a bitmap from a image in the phone. I then do various image manipulations to it like cropping, resizing, editing pixel values. </p>
  
  <p>But the problem is the format of the bitmap is not ARGB_8888, so its not really storing the alpha values. Or rather its always keeping them at 255.</p>
  
  <p>How can I load the bitmap in ARGB_8888 format? This is my code to load and resize.
  How can I specify the format in any of these?</p>
  
  <p>Thanks</p>
  
  <pre><code>private static Bitmap resize(Bitmap img, int newW, int newH) throws IOException {
      Bitmap resizedImg = Bitmap.createScaledBitmap(img, newW, newH, false);
      img.recycle();
  
      Bitmap newresizedImg = resizedImg.copy(Bitmap.Config.ARGB_8888, true);
      resizedImg.recycle();
  
  
      Pixel initialPixel = Function.getPixel(0, 0, newresizedImg, null);
      int a = initialPixel.getColor().getAlpha(); // -&gt; 255
      newresizedImg.setPixel(0, 0, Pixel.getTransparentColor().getRGB());
      initialPixel = Function.getPixel(0, 0, newresizedImg, null);
      int new_a = initialPixel.getColor().getAlpha(); // -&gt; 255
  
      return newresizedImg;
  }
  
  private static Bitmap getImage(String from) throws IOException {
      File file = new File(from);
  
      if (file.exists()) {
          BitmapFactory.Options op = new BitmapFactory.Options(); 
          op.inPreferredConfig = Bitmap.Config.ARGB_8888; 
          Bitmap bufferedImage = BitmapFactory.decodeFile(from, op);
          return bufferedImage;
      }
      return null;
  }
  </code></pre>
  
  <p>Pixel class</p>
  
  <pre><code>public static Color getTransparentColor() {
      return new Color(0, 0, 0, 0);
  }
  </code></pre>
  
  <p>Color class</p>
  
  <pre><code>public int getRGB() {
      return ((A &lt;&lt; 24) | 0xFF) + ((R &lt;&lt; 16) | 0xFF) + ((G &lt;&lt; 8) | 0xFF) + (B | 0xFF);
  }
  </code></pre>