title: Compress Bitmap before uploading
body: <p>Im using Facebook-Parse to upload a bitmap to the server (so in this case I'd like to use PNG/JPEG format since WEBP gives an error). Im able to upload the image successfully, what I want to know is if it can be made more efficient and if I can reduce the quality of the JPEG further? (NOTE: The images are going to be viewed fullscreen). </p>
  
  <pre><code>    public void save_DetailStory_ToParse()
  {
      DisplayMetrics displaymetrics = new DisplayMetrics();
      getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
      int height = displaymetrics.heightPixels;
      int width = displaymetrics.widthPixels;
      String filePath = iDataSave_path;
      final Bitmap bitmap = decodeSampledBitmapFromFilePath(getResources(), width, height, filePath.toString());
  
  
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream);
      byte[] image = stream.toByteArray();
      ParseFile file = new ParseFile("androidbegin.jpeg", image);
  
      pObject_storyDetail.put(KEY_IMAGE_FILE, file);
  
  
      pObject_storyDetailList.add(pObject_storyDetail);
  }
  
  public static Bitmap decodeSampledBitmapFromFilePath(Resources res, int reqWidth, int reqHeight, String filePath)
  {
  
      // First decode with inJustDecodeBounds=true to check dimensions
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(filePath, options);
  
      // Calculate inSampleSize
      options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
  
      // Decode bitmap with inSampleSize set
      options.inJustDecodeBounds = false;
  
      return BitmapFactory.decodeFile(filePath, options);
  }
  
  public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) 
  {
      // Raw height and width of image
      final int height = options.outHeight;
      final int width = options.outWidth;
  
      //int inSampleSize = 1;
      int inSampleSize = 2;
  
      if (height &gt; reqHeight || width &gt; reqWidth) 
      {
  
          final int halfHeight = height / 2;
          final int halfWidth = width / 2;
  
          // Calculate the largest inSampleSize value that is a power of 2 and keeps both
          // height and width larger than the requested height and width.
          while ((halfHeight / inSampleSize) &gt; reqHeight &amp;&amp; (halfWidth / inSampleSize) &gt; reqWidth) 
          {
              inSampleSize *= 2;
          }
      }
  
      return inSampleSize;
  }
  </code></pre>