4
public static void addBitmapToDisk(String filename, Bitmap paramBitmap,
            Context paramContext) {
        writeBitmapToDisk(filename, paramBitmap, paramContext,
                Bitmap.CompressFormat.PNG);
    }

    public static void writeBitmapToDisk(String filename, Bitmap paramBitmap,
            Context paramContext, Bitmap.CompressFormat paramCompressFormat) {
        String str = constructFileName(filename);
        if (paramBitmap != null) {
            try {
                FileOutputStream localFileOutputStream = paramContext
                        .openFileOutput(str, 0);
                Log.e("CL", "localFileOutputStream" + localFileOutputStream);
                paramBitmap.compress(paramCompressFormat, 100,
                        localFileOutputStream);
                localFileOutputStream.flush();
                localFileOutputStream.close();
                return;
            } catch (FileNotFoundException localFileNotFoundException) {
                localFileNotFoundException.printStackTrace();
                return;
            } catch (IOException localIOException) {
                localIOException.printStackTrace();
            }
        }
    }

When I have 2 Mb file it compress up to 100 Kb using above code snippet and image quality is not hd or very clear. so is there any method for quality maintain in android while bitmap compression like instagram

Swapnil
  • 654
  • 7
  • 27
  • Instagram degrades the quality of an image badly at the best of times. Compressing an image from 2MB (2048 kb) down to 100kb with a `lossy` compression is always going to degrade the quality a LOT. If you want it HD it's going to be bigger, or at least covert to a better format and don't expect miracles. You could make it much smaller if you want to keep the details. The file will be 4% its original size, with loss of fidelity. Compression like in the show "Silicon Valley" is not a real thing. Imaging compressing a 2Mb song to 100k, just how awful it would sound. – RossC Aug 21 '14 at 08:44
  • @RossC i can compromise with 100Kb size if it is bigger than that but i want image quality better – Swapnil Aug 21 '14 at 09:26
  • I'll have a look around, I had to write jpeg compression years ago in Java if I can find it. I'm just setting your expectation, 4% the file size will mean pretty rubbish quality with any lossy compression. To be honest, when I wrote it I ended up putting in a percentage value for the quality, and trial and error until I was happy with it. I'm not too familiar with bmp compression. – RossC Aug 21 '14 at 09:28
  • Hopefully someone with more knowledge than me (that is nearly everyone on this site) can chime in with more information. – RossC Aug 21 '14 at 09:39
  • Something else is wrong. It looks like youre trying to do png compression which should be lossless, i.e. no compression artifacts. – Aaron Sep 24 '14 at 17:26

0 Answers0