0

I just want to know the different factors on which I can work on and reduce the size of any image by maintaining its quality.

Like Bitmap.compress is the one option for me.

Also which is the best encoding format (Jpeg, Png) which maintain quality with minimal size.

tofi9
  • 5,775
  • 4
  • 29
  • 50
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62

3 Answers3

0

It depends of bitmap content. If you have a text or other solid color or contrast areas on your bitmap then PNG is your choice, because it preserves image quality.

If it's a picture from camera then JPG is best.

vadimvolk
  • 711
  • 4
  • 15
0
// try this way,hope this will help you...

private Bitmap decodeFileFromPath(String path){
        Uri uri = getImageUri(path);
        InputStream in = null;
        try {
            in = getContentResolver().openInputStream(uri);

            //Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;

            BitmapFactory.decodeStream(in, null, o);
            in.close();


            int scale = 1;
            int inSampleSize = 1024;
            if (o.outHeight > inSampleSize || o.outWidth > inSampleSize) {
                scale = (int) Math.pow(2, (int) Math.round(Math.log(inSampleSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
            }

            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            in = getContentResolver().openInputStream(uri);
            Bitmap b = BitmapFactory.decodeStream(in, null, o2);
            in.close();

            return b;

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0

Any lossless file format will not mess up with your bytes:

  • PNG (default configuration = lossless)
  • Tiff lossless (zip or lzw)
  • JPEG lossless (a special type of JPEG. I don't think Android supports this out of the box)
tofi9
  • 5,775
  • 4
  • 29
  • 50