title: Determine image size to reduce image size Android
body: <p>Is there away to reduce the image (taken from phone camera) storage capacity. As far as I know the parameters that can be changed are the quality, encoding and dimension of the image. For this I am using zetbaitsu/Compressor lib.</p>
  
  <p>The question is how to determine required dimensions for cloud storage, so that the image has good quality on various android screen sizes/resolutions while significantly reducing storage requirements.</p>
  
  <pre><code>File image = fileMessageContainer.getFile();
  BitmapFactory.Options bmOptions = new BitmapFactory.Options();
  bmOptions.inJustDecodeBounds = true;
  BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
  int width = bmOptions.outWidth;
  int height = bmOptions.outHeight;
  Log.d("myApp", "uncompressed" +  width + " height: " +  height);
  
  Bitmap bitmap = compressImages(image, width, height);
  Log.d("myApp", "compressed" +  bitmap.getWidth() + " height: " +  
  bitmap.getHeight());
  
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  byte[] byteArray = baos.toByteArray();
  
  Log.d("myApp", "original data " + byteArray.length);
  </code></pre>
  
  <hr>
  
  <pre><code>    private Bitmap compressImages(File actualImage, int width, int height){
          try {
           return new Compressor(context)
          .setQuality(75)
          .setMaxHeight(height)
          .setMaxWidth(width)
          .setCompressFormat(Bitmap.CompressFormat.JPEG)
          .compressToBitmap(actualImage);
          }catch (Exception e){
             Log.d("myApp", "compressImages-Error " + e.getMessage());
          }
          return null;
      }
  
      private byte[] convertToByteArray(Bitmap b){
          int bytes = b.getByteCount();
  
          ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
          b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
  
          return buffer.array(); //Get the underlying array containing the data.
      }
  </code></pre>
  
  <p>Console output</p>
  
  <p>uncompressed width: 2448 height: 3264
  compressed width: 2448 height: 3264
  original data 31961088</p>