user6008509
user6008509

Reputation:

Take a picture and reduce the quality

In my Android app, I have a button to take a picture like this :

button_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "fname_" +
                    String.valueOf(System.currentTimeMillis()) + ".jpg"));
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
            startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
        }
    });

and in my ActivityResult :

Intent intent = new Intent(this, UploadPicture.class);
            intent.putExtra("URI", imageUri.toString());
            startActivity(intent);

I would like to reduce the quality of my picture (I want a picture lighter for the server) before starting the activity of upload. How can I do that ?

Thanks

Upvotes: 1

Views: 510

Answers (1)

Praval Sharma
Praval Sharma

Reputation: 2143

Convert the image into Bitmap before uploading and compress the bitmap set the quality of the image and write it to the correct path.The quality of the image can be changed and hope this will help you to reduce the size of the image.

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

compress method is defined as

public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream)

You can take help from this also Bitmap.compress

Upvotes: 2

Related Questions