android how to change image storage size to 400K before upload to server

I Need to compress the image size after a taken a photo. I want to decrease the size to a maximum of 400K.

So, the average image size after taken the photo is about 3.3MB. I need to compress it to 400K.

What is the best option for this ?

I have tried :

Bitmap original = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
original.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

The code below allow me to reduce the size by way of width and height, but not is storage space.

Bitmap bitmap = Bitmap.createScaledBitmap(capturedImage, width, height, true);

Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.