title: compress image file from camera to certain size
body: <p>I'm trying to compress an image that I saved in the file. I'm trying to compress the File into 1MB. I try a few way but it usually make an OutofMemoryError.
  and then i tried to use this solution, but it makes the bitmap blank. </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/27415478/how-to-compress-bitmap-from-10mb-image-from-camera-to-300kb-beforw-setting-to-im">How to compress bitmap from 10mb image from camera to 300kb beforw setting to imageview in android</a></p>
  </blockquote>
  
  <p>Here is my code : </p>
  
  <pre><code>    System.gc();
      getActivity().getContentResolver().notifyChange(mImageTempUri, null);
      Bitmap bitmap;
      bitmap = BitmapFactory.decodeFile(mImageDirectory + mImageName, options);
      if(bitmap == null){
      howRequestFailedErrorMessage("Gambar gagal di-upload");
      return;
  
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();   
  
  
      bitmap.compress(Bitmap.CompressFormat.JPEG, 25, bytes);
      File f = new File(mImageDirectory + mImageName);
      if(f.exists()){
          f.delete();
      }
      FileOutputStream fo;
  
      try {
          fo = new FileOutputStream(f);
          fo.write(bytes.toByteArray());
          fo.flush();
          fo.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
      bitmap.recycle();
  </code></pre>