title: Resize Bitmap in Android
body: <p>I resize a bitmap using the following code:</p>
  <pre><code>FileOutputStream out = new FileOutputStream(&quot;/sdcard/mods.png&quot;);
  Bitmap bmp = Bitmap.createScaledBitmap(pict, (int)(pict.getWidth() / totScale),  
      (int)(pict.getHeight() / totScale), false);
  bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
  out.close();
  </code></pre>
  <p>The code for getting the bitmap from the camera that I am using is the following:</p>
  <pre><code>mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
          @Override
          public void onPictureTaken(byte[] data, Camera camera) {
              pict = BitmapFactory.decodeByteArray(data, 0, data.length);
          }
  });
  </code></pre>
  <p>The first picture is what I can see on the phone (in Astro file manager), and also when I draw the bitmap in my application on a canvas. This happens on every device I've tested on (HTC Legend and Galaxy Tab) The second picture is what it looks like on my computer. What is causing the blocks on the device?</p>
  <br>
  <h2>Solution:</h2>
  <p>Here is what fixed my problem:
  Instead of</p>
  <pre><code>pict = BitmapFactory.decodeByteArray(data, 0, data.length);
  </code></pre>
  <p>I replaced that with</p>
  <pre><code>BitmapFactory.Options opts = new BitmapFactory.Options();               
  opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
  pict = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
  </code></pre>
  <br>
  <p><img src="https://i.stack.imgur.com/Ap8Fd.png" alt="Phone" />
  <img src="https://i.stack.imgur.com/aU3Rt.png" alt="Computer" /></p>