Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce size of JPEG Image in Android

In my application, I am invoking the camera application and taking a picture and saving it in a particular directory (E.g. /sdcard etc)

The picture is saved as a JPEG image. How do I reduce the size of the image? Is there any available image encoder or compression available?

I came across another posting at: Android Reduce Size Of Camera Picture

But this is scaling the image. I am looking for something that can compress or encode. Is it possible?

Thanks In Advance, Perumal

like image 748
perumal316 Avatar asked Apr 17 '12 04:04

perumal316


People also ask

How do I reduce the size of a JPEG on my Android?

Step 1: Download and install 'Compress image size' from the Play Store. Step 2: Open the app and choose a photo. Step 3: You can check the original image size. Enable Quality toggle and use the slider to reduce image size.

How do I reduce the file size of a JPEG on my phone?

Here's how to reduce photo file size on Android phone using Google Photos: Open the Google Photos on your Android device. Select the photo that you want to compress. Hold on any photo to select multiple photos at once.


2 Answers

I am not sure anyway you can try this one.For reducing the size of the image first you should convert the image to bitmap before saving it to the particular directory, 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);` 

API:

compress (Bitmap.CompressFormat format, int quality, OutputStream stream)
like image 145
Sreedev Avatar answered Nov 04 '22 18:11

Sreedev


May be the below piece of code is useful for you

        opt = new BitmapFactory.Options();
        opt.inTempStorage = new byte[16 * 1024];
        opt.inSampleSize = 4;
        opt.outWidth = 640;
        opt.outHeight = 480;
        Bitmap imageBitmap = BitmapFactory
                .decodeStream(in, new Rect(), opt);
        Bitmap map = Bitmap.createScaledBitmap(imageBitmap, 100, 100, true);
        BitmapDrawable bmd = new BitmapDrawable(map);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        map.compress(Bitmap.CompressFormat.PNG, 90, bao);
        ba = bao.toByteArray();
        imagedata=Base64.encodeBytes(ba);
like image 29
Manju Avatar answered Nov 04 '22 18:11

Manju