title: How to reduce an Image file size before uploading to a server
body: <p>Lot of application allow sharing an image, which is picked from the gallery.</p>
  
  <p>Do they upload the original image file? Which is like 1-3 mb? Or do they process?</p>
  
  <p>In any case, how can I take the image from a filepath, reduce its size by lowering the resolution and save it some where else and the try to upload?</p>
  
  <p><strong>I tried:</strong></p>
  
  <pre><code>Bitmap photo = decodeSampledBitmapFromFile(filePath, DESIRED_WIDTH,
                      DESIRED_HEIGHT);
  
  FileOutputStream out = new FileOutputStream(filePath);
  photo.compress(Bitmap.CompressFormat.JPEG, 100, out);
  
  public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth,
          int reqHeight) {
  
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(path, options);
  
      final int height = options.outHeight;
      final int width = options.outWidth;
      options.inPreferredConfig = Bitmap.Config.ARGB_8888;
      int inSampleSize = 1;
  
      if (height &gt; reqHeight) {
          inSampleSize = Math.round((float) height / (float) reqHeight);
      }
      int expectedWidth = width / inSampleSize;
  
      if (expectedWidth &gt; reqWidth) {
          inSampleSize = Math.round((float) width / (float) reqWidth);
      }
      options.inSampleSize = inSampleSize;
      options.inJustDecodeBounds = false;
      return BitmapFactory.decodeFile(path, options);
  }
  </code></pre>
  
  <p>But is this they right way to do? Because I have seen answers suggesting <code>compression operation takes rather big amount of time</code> <a href="https://stackoverflow.com/questions/11061280/android-reduce-image-file-size">here</a></p>