title: Resize image from +1mb taken from camera intent to <=150k Android
body: <p>I am trying to reduce the size of picture taken from camera and gallery (1+mb to 150k. both). </p>
  
  <ol>
  <li><p>code to take photo:</p>
  
  <pre><code>Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  
  //intent.putExtra("crop", "true");
  
  intent.putExtra("outputX", 50);
  
  intent.putExtra("outputY", 50);
  
  intent.putExtra("aspectX", 1);
  
  intent.putExtra("aspectY", 1);
  
  intent.putExtra("outputX", 128);
  
  intent.putExtra("outputY", 128);
  
  intent.putExtra("scaleUpIfNeeded", true);
  
  intent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG.toString());
  
  intent.putExtra("return-data", false);
  
  intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
  
  startActivityForResult(intent, PICTURE_RESULT);
  </code></pre></li>
  <li><p>intent to select from gallery</p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
  intent.setType("image/*");
  
  //intent.putExtra("crop", "true");
  
  intent.putExtra("outputX", 50);
  
  intent.putExtra("outputY", 50);
  
  intent.putExtra("aspectX", 1);
  
  intent.putExtra("aspectY", 1);
  
  intent.putExtra("scale", true); 
  
  intent.putExtra("scaleUpIfNeeded", true);
  
  intent.putExtra("return-data", true);
  
  intent.putExtra(MediaStore.EXTRA_OUTPUT,destination);
  intent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG.toString());
  
  startActivityForResult(Intent.createChooser(intent, "Choisir Photo"),SELECT_FILE);
  </code></pre></li>
  </ol>
  
  <p>My activity result is as follows </p>
  
  <pre><code>@Override
  
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  
          super.onActivityResult(requestCode, resultCode, data);
  
          if (resultCode == PICTURE_RESULT) {
  
              if (requestCode == REQUEST_CAMERA) {
  
                  Editer.PHOTO_FROM=11;
  
                  File f = new File(Environment.getExternalStorageDirectory()
                          .toString());
  
                  for (File temp : f.listFiles()) {
  
                      if (temp.getName().equals("temp.jpg")) {
  
                          f = temp;
  
                          break;
  
                      }
  
                  }
  
                  //Uri.fromFile(createFile());
  
                  Constant.filePath=f.getAbsolutePath();
  
                  String fname = "user_image_golf.jpg";
  
                  BitmapFactory.Options options = new BitmapFactory.Options();
  
                  options.inTempStorage = new byte[16 * 1024];
  
                  options.inSampleSize = 4;
  
                  options.outWidth = 100;
  
                  options.outHeight = 100;
  
                  String root = Environment.getExternalStorageDirectory().toString();
  
                  File myDir = new File(root + "user_image_golf.jpg");   // == /
                  myDir.mkdirs();
  
                  destination = new 
  File(Environment.getExternalStorageDirectory(),"user_image_golf.jpg");
  
  
                  Bitmap bitmap = BitmapFactory.decodeFile(destination.toString(), options);
  
                  Bitmap map = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
                  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  
                  map.compress(Bitmap.CompressFormat.PNG, 50, bao);
  
                  //byte[] ba = bao.toByteArray();
  
                  File file = new File (myDir, f.getAbsolutePath());
  
                  if (file.exists ()) file.delete ();
  
                  try {
  
                      FileOutputStream out = new FileOutputStream(file);
  
                      map.compress(Bitmap.CompressFormat.JPEG, 20, out);
  
                      out.flush();
  
                      out.close();
  
                  } catch (Exception e) {
  
                      e.printStackTrace();
                  }
  
                  System.out.println("//imagedata=Base64.encodeBytes(ba);");
  
                  ///imagedata=Base64.encodeBytes(ba);
  
                  //rotateImage(Uri.fromFile(destination).toString());
  
              }
  
  
              else if (requestCode == SELECT_FILE) {
  
                  Uri selectedImageUri = data.getData();
  
                  Constant.filePath =selectedImageUri.toString();
  
                  Editer.PHOTO_FROM=2;
  
                  System.out.println("getAbsolutePath() "+selectedImageUri);
  
                  System.out.println("selectedImageUri-getAbsolutePath()
   "+getPath(selectedImageUri,m));
  
  
              }
  
          }
          m.finish();
  
      }
  </code></pre>
  
  <p>If i select a photo from gallery or take a picture from camera, the new photo from camera or latest selected image from gallery should override the photo saved on sd card.</p>