title: How to reduce image size into 1MB
body: <p>I want my application to upload image with no size limit, but in the code, I want to resize  the image into 1MB if the image size exceeds. I have tried many ways but I couldn't find any code for the requirement I have mentioned above.</p>
  
  <p>For once, I have tried this: </p>
  
  <pre><code>public void scaleDown() {
      int width = stdImageBmp.getWidth();
      int height = stdImageBmp.getHeight();
      Matrix matrix = new Matrix();
      float scaleWidth = ((float) MAX_WIDTH) / width;
      float scaleHeight = ((float) MAX_HEIGHT) / height;
  
  
      matrix.postScale(scaleWidth, scaleHeight);
      stdImageBmp = Bitmap.createBitmap(stdImageBmp, 0, 0, width, height, matrix, true);
  
      File Image = new File("path");
  
  
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      //compress bmp
      stdImageBmp.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
      byte[] byteArray = byteArrayOutputStream.toByteArray();
  
  
      imgViewStd.setImageBitmap(stdImageBmp);
      Log.d("resizedBitmap", stdImageBmp.toString());
  
      width = stdImageBmp.getWidth();
      height = stdImageBmp.getHeight();
      System.out.println("imgWidth" + width);
      System.out.println("imgHeight" + height);
  }
  </code></pre>